Parse json for sectioned UITableView in iOS - ios

I am trying to display State (in section title) and City (in table rows) from this url. Top Cities will come in first section followed by state and cities. Issue is I am not able to assign respective array of cities for sectioned state title row. Here's what I tried..
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
NSLog(#"Json dictionary = %#", json);
self.dictListSateMaster = [json objectForKey:#"RaffleInstanceLocations"];
for (NSDictionary *dict in [self.dictListSateMaster objectForKey:#"listStateMaster"])
{
ViewLocationsObjct *viewLocationsObjct = [[ViewLocationsObjct alloc] init];
viewLocationsObjct.StateNameStr = [dict objectForKey:#"StateName"];
[self.arrayListStateMaster addObject:[dict objectForKey:#"StateName"]];
for (NSDictionary *dictnry in [dict objectForKey:#"listCityMaster"])
{
//*********-- Need corrections here
ViewLocationStateMaster *viewLocNewObjct = [[ViewLocationStateMaster alloc] init];
viewLocNewObjct.CityName = [dictnry objectForKey:#"CityName"];
[self.arrayListCityMaster addObject:viewLocNewObjct];
}
}
for (NSDictionary *dict in [self.dictListSateMaster objectForKey:#"listTopCities"])
{
ViewLocationsObjct *viewLocationsObjct = [[ViewLocationsObjct alloc] init];
viewLocationsObjct.CityName = [dict objectForKey:#"CityName"];
[self.arrayTopCities addObject:viewLocationsObjct];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return self.arrayListStateMaster.count+1; //+1 to append to top cities section at the top
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellId = #"cellId";
ViewLocationsTblCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId forIndexPath:indexPath];
if (indexPath.section == 0)
{
ViewLocationsObjct *viewLocationObj = [self.arrayTopCities objectAtIndex:indexPath.row];
cell.locationLabl.text = viewLocationObj.CityName;
}
else
{
//*********-- Need corrections here
//NSString *sectionTitle = [self.arrayListStateMaster objectAtIndex:indexPath.section];
//NSMutableArray *arrayCities = [self.dictListSateMaster objectForKey:sectionTitle];
//cell.locationLabl.text = [arrayCities objectAtIndex:indexPath.row];
ViewLocationStateMaster *viewLoc = [self.arrayListCityMaster objectAtIndex:indexPath.row];
cell.locationLabl.text = viewLoc.CityName;
}
return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (section == 0)//return top cities for 1st section
{
return self.arrayTopCities.count;
}
else
{
return self.arrayListCityMaster.count;
}
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
if (section == 0)
{
return #"Top Cities";
}
else
{
if (self.arrayListStateMaster.count > 0)
{
return [self.arrayListStateMaster objectAtIndex:section-1];//-1 to remove index of top cities section at the top
}
else
{
return #"";
}
}
}

OK so here's how my problem was solved !
NSDictionary *dictRaffleInstLocations = [json objectForKey:#"RaffleInstanceLocations"];
sectionArray = [dictRaffleInstLocations objectForKey:#"listStateMaster"];
topCityArray = [dictRaffleInstLocations objectForKeyedSubscript:#"listTopCities"];
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (section == 0) {
return topCityArray.count;
}else
return [[[sectionArray objectAtIndex:section-1]objectForKey:#"listCityMaster"] count];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return sectionArray.count+1;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
if (section == 0) {
return #"Top Cities";
}else
return [[sectionArray objectAtIndex:section-1]objectForKey:#"StateName"];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellId = #"MyCellLocation";
ViewLocationsTblCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId forIndexPath:indexPath];
if ([UIDevice currentDevice].systemVersion.floatValue >= 8.0f)
{
cell.layoutMargins = UIEdgeInsetsZero;
cell.preservesSuperviewLayoutMargins = NO;
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
NSString *titleString = #"";
if (indexPath.section == 0) {
titleString = [[topCityArray objectAtIndex:indexPath.row]objectForKey:#"CityName"];
}else{
NSArray *cityArray = [sectionArray[indexPath.section-1]objectForKey:#"listCityMaster"];
titleString = [cityArray[indexPath.row]objectForKey:#"CityName"];
}
cell.locationLabl.text = titleString;
return cell;
}

Related

Multi-select cell in UITableView in sequence

I have a UITableView with numerous cells. I'm able to multi select cells but what I want is that user only can select multiple cells in sequence. ie if user has selected 2nd row then he/she only can select 3rd cell then 4th in sequence, doesn't allow to select random cells.
Here is what I've done:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return arrPackages.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
PurchaseListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"PurchaseListTableViewCell" forIndexPath:indexPath];
NSDictionary *dict = [arrPackages objectAtIndex:indexPath.row];
cell.lblPackageName.text = [dict valueForKey:#"package_name"];
cell.lblDiscount.text = [NSString stringWithFormat:#"You save: %#%%",[dict valueForKey:#"discount"]];
cell.lblLastAmount.text = [NSString stringWithFormat:#"%#",[dict valueForKey:#"package_price"]];
NSString *strPaymentStatus = [NSString stringWithFormat:#"%#",[dict valueForKey:#"payment_status"]];
if ([strPaymentStatus isEqualToString:#"2"]) {
cell.contentView.userInteractionEnabled = NO;
}
else{
cell.contentView.userInteractionEnabled = YES;
}
/*
NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:#"Your String here"];
[attributeString addAttribute:NSStrikethroughStyleAttributeName
value:#2
range:NSMakeRange(0, [attributeString length])];
*/
return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 100;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// NSDictionary *dict = [_arrModuleData objectAtIndex:indexPath.row];
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewCellEditingStyleDelete | UITableViewCellEditingStyleInsert;
}
You can implement the tableview delegate method tableView(_:willSelectRowAt:) and return nil if you don't want to select the current index path, else you just return the given index path.
Objective-C:
-(NSIndexPath*)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSArray<NSIndexPath *> *selectedIndexPaths = [tableView indexPathsForSelectedRows];
if (selectedIndexPaths == nil || selectedIndexPaths.count == 0) {
return indexPath;
}
NSArray<NSIndexPath *> *sortedIndexPaths = [[selectedIndexPaths sortedArrayUsingComparator:^NSComparisonResult(NSIndexPath * _Nonnull index1, NSIndexPath * _Nonnull index2) {
return index1.row < index2.row;
}] filteredArrayUsingPredicate:[NSPredicate predicateWithFormat: #"section = %d", indexPath.section]];
if (indexPath.row >= sortedIndexPaths[0].row &&
indexPath.row <= sortedIndexPaths[sortedIndexPaths.count-1].row) {
return indexPath;
}
return nil;
}
Swift:
func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? {
guard let selectedIndexPaths = tableView.indexPathsForSelectedRows,
selectedIndexPaths.count > 0 else {
return indexPath
}
let indexes = selectedIndexPaths
.filter { $0.section == indexPath.section }
.sorted()
if let first = indexes.first,
let last = indexes.last,
indexPath.row >= first.row - 1 && indexPath.row <= last.row + 1 {
return indexPath
}
return nil
}
Of course you should code a similar behavior for tableView(_:willDeselectRowAt:)

How to group UITableView with section mentioned in JSON value

I get this json from web service and I need to group it depending on "PRICELISTCATEGORY" value. I tried the following code, but I get repeated rows and sections in the table. I collect the web service array in self.arrayPriceList. What am I doing wrong?
After collecting the array from json web service, I call [self didReceiveResponseJson:self.arrayPriceList];
-(NSMutableDictionary *)priceListCategoryDitionaryAllReadyExist:(NSString *)price {
for(NSMutableDictionary *priceListDict in self.arrayPriceList){
if([[[priceListDict objectForKey:#"PRICELISTCATEGORY"] objectForKey:#"text"] isEqualToString:price])
//return the existing array refrence to add
return priceListDict;
}
// if we dont found then we will come here and return nil
return nil;
}
-(void)didReceiveResponseJson:(NSMutableArray *)jsonArray {
for(NSDictionary *priceDict in jsonArray) {
NSMutableDictionary *existingPriceListDict=[self priceListCategoryDitionaryAllReadyExist:[[priceDict objectForKey:#"PRICELISTCATEGORY"] objectForKey:#"text"]];
NSMutableArray *existingTempArray = [NSMutableArray array];
if(existingPriceListDict != nil) {
//if name exist add in existing array....
[existingTempArray addObject:priceDict];
}
else {
// create new price list array
NSMutableArray *newPriceListArray=[[NSMutableArray alloc] init];
// Add name dictionary in it
[newPriceListArray addObject:priceDict];
// add this newly created pricelist array in globalNameArray
[self.arrayPriceList addObject:newPriceListArray];
}
}
//so at the end print global array you will get dynamic array with the there respetive dict.
//NSLog(#"Table array %#", self.arrayPriceList);
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
TGAPriceListCell *cell = [tableView dequeueReusableCellWithIdentifier:#"TGAPriceListCellId" forIndexPath:indexPath];
NSDictionary *dict;
if (self.isFiltered) {
dict = [self.arrayFilteredPriceList objectAtIndex:indexPath.row];
} else {
dict = [self.arrayPriceList objectAtIndex:indexPath.section];
}
cell.lblAPNBarCode.text = [[dict objectForKey:#"APNBARCODE"] objectForKey:#"text"];
cell.lblAvgCost.text = [[dict objectForKey:#"AVERAGECOST"] objectForKey:#"text"];
return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (self.isFiltered) {
return self.arrayFilteredPriceList.count;
} else {
NSArray *arrayPrice = [self.arrayPriceList objectAtIndex:section];
return [arrayPrice count];
}
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return [self.arrayPriceList count];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
NSDictionary *arrayPrice = [self.arrayPriceList objectAtIndex:section];
if([arrayPrice count]) {
return [[arrayPrice objectForKey:#"PRICELISTCATEGORY"] objectForKey:#"text"];
}
else
return nil;
}
After calling didReceiveResponseJson in viewDidLoad
self.arrayPriceList = [NSMutableArray array];
self.dictPriceList = [NSMutableDictionary dictionary];
I made changes in tableview datasource methods
-(void)didReceiveResponseJson:(NSMutableArray *)jsonArray {
for (NSDictionary *dict in jsonArray ) {
NSString *strPriceListCategory = [[dict objectForKey:#"PRICELISTCATEGORY"] objectForKey:#"text"];
if ([[self.dictPriceList allKeys] containsObject:strPriceListCategory]) {
NSMutableArray *arrayTemp = [self.dictPriceList objectForKey:strPriceListCategory];
[arrayTemp addObject:dict];
[self.dictPriceList setObject:arrayTemp forKey:strPriceListCategory];
} else {
NSMutableArray *arrayTemp = [[NSMutableArray alloc] initWithObjects:dict, nil];
[self.dictPriceList setObject:arrayTemp forKey:strPriceListCategory];
}
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
TGAPriceListCell *cell = [tableView dequeueReusableCellWithIdentifier:#"TGAPriceListCellId" forIndexPath:indexPath];
NSDictionary *dict;
if (self.isFiltered) {
dict = [self.arrayFilteredPriceList objectAtIndex:indexPath.row];
} else {
NSArray *arrayPriceListAllKeys = [self.dictPriceList allKeys];
NSArray *arrayPrice = [self.dictPriceList objectForKey:[arrayPriceListAllKeys objectAtIndex:indexPath.section]];
dict = [arrayPrice objectAtIndex:indexPath.row];
}
cell.lblAPNBarCode.text = [[dict objectForKey:#"APNBARCODE"] objectForKey:#"text"];
cell.lblAvgCost.text = [[dict objectForKey:#"AVERAGECOST"] objectForKey:#"text"];
return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (self.isFiltered) {
return self.arrayFilteredPriceList.count;
} else {
NSArray *arrayPriceListAllKeys = [self.dictPriceList allKeys];
NSArray *arrayPrice = [self.dictPriceList objectForKey:[arrayPriceListAllKeys objectAtIndex:section]];
return [arrayPrice count];
}
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return [[self.dictPriceList allKeys] count];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
NSString *price = [[self.dictPriceList allKeys] objectAtIndex:section];
return price;
}

How to move row to another Section while clicking on row?

I have Implemented multi select row but what i have to do is when we click on row it will move on another section , Here's my code what i have tried is ?
can anyone help me out from this ? Thanks in advance ...
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 2; //assuming you have only two sections
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (section == 0)
return self.firstSectionDataSource.count;
else if (section == 1)
return self.dataArray.count;
else
return 0;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Here, Have to move row to another section while clcking ..
// other multiselect code
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// Configure a cell to show the corresponding string from the array.
static NSString *kCellID = #"cellID";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellID];
cell.textLabel.text = [self.dataArray objectAtIndex:indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
{
#try {
NSMutableArray *sourceArray = nil;
if (sourceIndexPath.section == 0) {
sourceArray = self.firstSectionDataSource;
}
else if (sourceIndexPath.section == 1)
{
sourceArray = self.dataArray;
}
NSMutableArray *destinationArray = nil;
if (destinationIndexPath.section == 0) {
destinationArray = self.firstSectionDataSource;
}
else if (destinationIndexPath.section == 1)
{
destinationArray = self.dataArray;
}
NSString *stringToMov = [sourceArray objectAtIndex:sourceIndexPath.row];
[sourceArray removeObject:stringToMov];
[destinationArray insertObject:stringToMov atIndex:destinationIndexPath.row];
}
#catch (NSException *exception) {
NSLog(#"exception = %# \n reason = %#",exception,exception.reason);
}
}
In cellForRowAtIndexPath
[cell setShowsReorderControl:YES];
And you need to implement the following UITableView delegate and data source methods properly
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 2; //assuming you have only two sections
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (section == 0)
return firstSectionDataSource.count;
else if (section == 1)
return secondSectionDataSource.count;
else
return 0;
}
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
{
#try {
NSMutableArray *sourceArray = nil;
if (sourceIndexPath.section == 0) {
sourceArray = firstSectionDataSource;
}
else if (sourceIndexPath.section == 1)
{
sourceArray = secondSectionDataSource;
}
NSMutableArray *destinationArray = nil;
if (destinationIndexPath.section == 0) {
destinationArray = firstSectionDataSource;
}
else if (destinationIndexPath.section == 1)
{
destinationArray = secondSectionDataSource;
}
NSString *stringToMov = [[sourceArray objectAtIndex:sourceIndexPath.row] retain];
[sourceArray removeObject:stringToMov];
[destinationArray insertObject:stringToMov atIndex:destinationIndexPath.row];
[stringToMov release];
}
#catch (NSException *exception) {
NSLog(#"exception = %# \n reason = %#",exception,exception.reason);
}
}
You can do the next:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView moveRowAtIndexPath:indexPath toIndexPath:[NSIndexPath indexPathForRow:row inSection:section]];
// other multiselect code
}
Try this -
NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithObjects:[NSArray arrayWithObjects:[NSArray arrayWithObjects:#"a",#"b",#"c", nil],[NSArray arrayWithObjects:#"d",#"e",#"f", nil], nil] forKeys:[NSArray arrayWithObjects:#"firstSection",#"secondsection", nil]];
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [[dict allKeys] count]; //assuming you have only two sections
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [[dict objectForKey:[dict allKeys][section]] count];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSMutableArray *arr = [dict objectForKey:[dict allKeys][indexPath.section]];
NSString *str = arr[indexPath.row];
if (indexPath.row!=0) {
[arr removeObject:str];
}
NSMutableArray *arr1 = [dict objectForKey:[dict allKeys][0]];
[arr1 addObject:str];
[tableView reloadData];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSArray *arr = [dict objectForKey:[dict allKeys][indexPath.section]];
NSString *str = arr[indexPath.row];
static NSString *kCellID = #"cellID";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellID];
cell.textLabel.text = str;
return cell;
}

grouped tableview showing the same row values for different sections

I have created a grouped tableview. i have 3 sections in that and trying to display different rows for all the sections using 1 array. but it is showing the same cell text for all the sections. here is the delegate methods which i implemented.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
mSectionArray = [NSArray arrayWithObjects:#"abc", #"def",#"ghi", nil] ;
return [mSectionArray count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if(section == 0) {
mContentArray = [NSArray arrayWithObjects:#"hello",#"hello1", nil];
}
if(section == 1) {
mContentArray = [NSArray arrayWithObjects:#"one", #"two",#"three",#"four",#"five", nil];
NSLog(#"section 1 %#",mContentArray);
}if (section == 2){
mContentArray = [NSArray arrayWithObjects:#"abc", nil];
}
return [mContentArray count];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
NSString *sectionHeader = nil;
if(section == 0) {
sectionHeader = #"abc";
}
if(section == 1) {
sectionHeader = #"def";
}
if (section == 2) {
sectionHeader = #"ghi";
}
return sectionHeader;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = nil;
cell = [tableView dequeueReusableCellWithIdentifier:#"Cell"];
if(!cell){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:#"Cell"];
}
cell.textLabel.text = [mContentArray objectAtIndex:indexPath.row];
cell.textLabel.textColor = [UIColor darkGrayColor];
return cell;
}
it is showing "one" "two" "three" etc in all sections but i want different values for different sections. please help me in solving the issue.
Your array should be like that:
intialize in viewDidLoad
mContentArray = [[NSMutableArray alloc]init];
NSArray * araray1 = [[NSArray alloc] initWithObjects:#"hello",#"hello1", nil];
NSArray * araray2 = [[NSArray alloc] initWithObjects:#"one", #"two",#"three",#"four",#"five", nil];
NSArray * araray3 = [[NSArray alloc] initWithObjects:#"abc", nil];
[mContentArray addObject:araray1];
[mContentArray addObject:araray2];
[mContentArray addObject:araray3];
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [mContentArray count];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [[mContentArray objectAtIndex:section]count];
}
while retrieving
cell.textLabel.text = [[mContentArray objectAtIndex:indexPath.section]objectAtIndex:indexPath.row];

UIAlertView in cell

i have a UITableView and i want a specific cell to be an alert view when i touch it.
how could i do that please?
how to load an alertView into the cells ?
#synthesize courses, courseKeys, courses_web, courseKeys_web;
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (section == 0) {
return [courses count];
} else {
return [courses_web count];
}
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
if (section == 0) {
return #"iOS Courses";
} else {
return #"Web Courses";
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"cell"];
if (cell == nil) {
cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:#"cell"];
}
NSString *currentCourseName;
// Which section are we in?
if ([indexPath section] == 0) {
currentCourseName = [courseKeys objectAtIndex:indexPath.row];
} else {
currentCourseName = [courseKeys_web objectAtIndex:indexPath.row];
}
[[cell textLabel] setText:currentCourseName];
// Now, get the author name
NSString *currentAuthorName;
if ([indexPath section] == 0) {
currentAuthorName = [courses objectForKey:[courseKeys objectAtIndex:indexPath.row]];
} else {
currentAuthorName = [courses_web objectForKey:[courseKeys_web objectAtIndex:indexPath.row]];
}
[[cell detailTextLabel] setText:currentAuthorName];
// Retrieve an image
NSString *imagefile = [[NSBundle mainBundle] pathForResource:#"cellimage" ofType:#"png"];
UIImage *image = [[UIImage alloc] initWithContentsOfFile:imagefile];
// Add the image to the table cell
[[cell imageView]setImage:image];
// accessory type
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
return cell;
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *myfile = [[NSBundle mainBundle]
pathForResource:#"courses" ofType:#"plist"];
courses = [[NSDictionary alloc] initWithContentsOfFile:myfile];
courseKeys = [courses allKeys];
myfile = [[NSBundle mainBundle]
pathForResource:#"courses_web" ofType:#"plist"];
courses_web = [[NSDictionary alloc] initWithContentsOfFile:myfile];
courseKeys_web = [courses_web allKeys];
On Selection of tableCell,Add UIAlertView in didSelectRowAtIndexPath delegate method.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row == //specific row)
{
// show alert view
}
}

Resources