I've a problem, when I'm refreshing my tableView more then 5-6(+/-) times in a row, I'm having exec bad access in the following methods:
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
NSArray *messages = [HumanResponse allAcceptedRecords];
if (messages != nil && messages.count > 0) {
CoreDataPhotoRecord *photoDetails = (CoreDataPhotoRecord *)messages[indexPath.row];
if (photoDetails != nil) {
==> HERE==> if (photoDetails.message != nil) {
if (photoDetails.message.flag.integerValue == FLAG_NOT_HANDLED) {
return YES;
}
}
}
}
return NO;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
id globalCell;
CoreDataPhotoRecord *photoDetails = nil;
if (self.searchDisplayController.isActive) {
photoDetails = self.searchResults[indexPath.row];
}
else {
NSArray *results = [HumanResponse allAcceptedRecords];
if (results.count > 0) {
photoDetails = results[indexPath.row];
}
}
==> HERE==> if (photoDetails != nil && photoDetails.message != nil && [self isNormanMessageCell:photoDetails.message.type.integerValue]) {
MessageCell *cell = (MessageCell *)[tableView dequeueReusableCellWithIdentifier:kMessageCellID
forIndexPath:indexPath];
if (cell == nil) {
cell = (MessageCell *)[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:kMessageCellID];
}
if (tableView.isEditing) {
[cell setSelectionStyle:UITableViewCellSelectionStyleDefault];
} else {
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
}
And Related Method (I guess):
+ (NSArray *)allAcceptedRecords
{
// Permanent
NSArray *results = [CoreDataPhotoRecord MR_findAllSortedBy:#"message.originalDate"
ascending:NO
withPredicate:[NSPredicate predicateWithFormat:#"message.delete_message == %#", #NO]];
return results;
}
I don't know what is wrong here since I'm always checking if this variable is not nil, so it keep crashing?
As I said, for the first 5-6 times(+/-), it doesn't crash but trying once again right after will make it crash.
An I missing something?
Related
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;
}
This question already has answers here:
what if when two UITableView in one ViewController and one with custom cell refrence and another is a simple
(6 answers)
Closed 8 years ago.
The attached code is returning an error:
Control may reach end non-void function
Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 0) {
FirstCustomCell *fCustomCell = [tableView dequeueReusableCellWithIdentifier:#"firstCustomCell" forIndexPath:indexPath];
if (fCustomCell == nil) {
fCustomCell = [[FirstCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"firstCustomCell"];
}
return fCustomCell;
}
else if (indexPath.row == 1) {
SecondCustomCell *sCustomCell = [tableView dequeueReusableCellWithIdentifier:#"secondCustomCell" forIndexPath:indexPath];
if (sCustomCell == nil) {
sCustomCell = [[SecondCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"SecondCustomCell"];
}
return sCustomCell;
}
} //<-- Control may reach non-void function (I precise that's the end of the cellForRowAtIndexPath method)
I know that the problem is specially at the "return" but how do I eliminate the error?
You account for the cases where indexPath.row == 0 and where indexPath.row == 1 but the compiler is saying: What should I return if the row isn't 0 or 1?
You probably want a return nil; at the end of your method.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == 0)
{
FirstCustomCell *fCustomCell = [tableView dequeueReusableCellWithIdentifier:#"firstCustomCell" forIndexPath:indexPath];
if (fCustomCell == nil)
{
fCustomCell = [[FirstCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"firstCustomCell"];
}
return fCustomCell;
}
else if (indexPath.row == 1)
{
SecondCustomCell *sCustomCell = [tableView dequeueReusableCellWithIdentifier:#"secondCustomCell" forIndexPath:indexPath];
if (sCustomCell == nil)
{
sCustomCell = [[SecondCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"secondCustomCell"];
}
return sCustomCell;
}
return nil; //<--Add this line
}
Or perhaps an "else" case:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == 0)
{
FirstCustomCell *fCustomCell = [tableView dequeueReusableCellWithIdentifier:#"firstCustomCell" forIndexPath:indexPath];
if (fCustomCell == nil)
{
fCustomCell = [[FirstCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"firstCustomCell"];
}
return fCustomCell;
}
else if (indexPath.row == 1)
{
SecondCustomCell *sCustomCell = [tableView dequeueReusableCellWithIdentifier:#"secondCustomCell" forIndexPath:indexPath];
if (sCustomCell == nil)
{
sCustomCell = [[SecondCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"secondCustomCell"];
}
return sCustomCell;
}
else //<--Add this clause
{
OtherCustomCell *oCustomCell = [tableView dequeueReusableCellWithIdentifier:#"otherCustomCell" forIndexPath:indexPath];
if (oCustomCell == nil)
{
oCustomCell = [[OtherCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"otherCustomCell"];
}
return sCustomCell;
}
}
Note: You also have a typo in your reuse identifiers:
"secondCustomCell" is not the same as "SecondCustomCell"
Add a return nil; line.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 0) {
FirstCustomCell *fCustomCell = [tableView dequeueReusableCellWithIdentifier:#"firstCustomCell" forIndexPath:indexPath];
if (fCustomCell == nil) {
fCustomCell = [[FirstCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"firstCustomCell"];
}
return fCustomCell;
}
else if (indexPath.row == 1) {
SecondCustomCell *sCustomCell = [tableView dequeueReusableCellWithIdentifier:#"secondCustomCell" forIndexPath:indexPath];
if (sCustomCell == nil) {
sCustomCell = [[SecondCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"SecondCustomCell"];
}
return sCustomCell;
}
return nil;
}
I might add that you need to make sure that you fCustomCell and your sCustomCell are not (!=) nil.
if (!fCustomCell) {
fCustomCell = [UITableViewCell alloc] initWithStyle:/*aStyle*/ reuseIdentifier:/*identifier*/];
}
The identifier can be a static NSString defined at the beginning of the method like so: static NSString *identifier = #"cell";
Look at some tutorials.
i need to add checkmark when we tap on each cell, and it must show when i return back to tableview.
I tried with this code but its not working,
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
if (self.thread == nil) {
cell.textLabel.text = #"Loading, please wait...";
} else if ([self.thread count] == 0) {
cell.textLabel.text = #"No Results!";
} else {
//
NSDictionary *msg = [self.thread objectAtIndex:indexPath.row];
NSLog(#"yourMutableDictionary - %#",msg);
if (indexPath.row == 0) {
cell.textLabel.text = [thread objectAtIndex:0];
} else {
cell.textLabel.text = [NSString stringWithFormat:#"%# ", [msg objectForKey:#"id"]];
if ([self.idSelected count] != 0) {
if ([self.idSelected containsObject:[NSString stringWithFormat:#"%#", [msg objectForKey:#"id"]]]) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
}
}
}
return cell;
}
#pragma mark - Table view delegate
//In a xib-based application, navigation from a table can be handled in - tableView:didSelectRowAtIndexPath:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)path
{
if (self.thread == nil || self.thread.count == 0) {
return;
}
UITableViewCell *cell = [tableView cellForRowAtIndexPath:path];
if (path.row == 0) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;// this checkmark not working
}
else {
NSDictionary *user = [self.thread objectAtIndex:path.row];
NSString *uName = [NSString stringWithFormat:#"%# %#", [user objectForKey:#"first_name"], [user objectForKey:#"last_name"]];
NSString *uId = [NSString stringWithFormat:#"%#",[user objectForKey:#"id"]];
NSLog(#" click id%#", uId);
if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {
[userNames removeObject:uName];
[userIds removeObject:uId ];
cell.accessoryType = UITableViewCellAccessoryNone; // this check mark is working perfectly
} else {
[userNames addObject:uName];
[userIds addObject:uId];
cell.accessoryType = UITableViewCellAccessoryCheckmark; // this check mark is working perfectly
}
}
}
first cell check mark is not working but others working perfectly. I want to add check mark on first cell too, how its possible
Use below code to display checkmark on multiple table view cell :
- (void)viewDidLoad
{
[super viewDidLoad];
self.arraySelectedCell = [NSMutableArray array];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([self.arraySelectedCell containsObject:indexPath])
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else
{
cell.accessoryType = UITableViewCellAccessoryNone;
}
// do here..
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
//the below code will allow multiple selection
if ([self.arraySelectedCell containsObject:indexPath])
{
[self.arraySelectedCell removeObject:indexPath];
}
else
{
[self.arraySelectedCell addObject:indexPath];
}
[tableView reloadData];
}
happy coding!
I have the following search setup in my app:
- (UISearchBar*)searchBar
{
if (!_searchBar) {
_searchBar = [[UISearchBar alloc] init];
_searchBar.delegate = self;
_searchBar.placeholder = kSearchBarPlaceHolder;
}
return _searchBar;
}
- (UISearchDisplayController*)searchBarDisplayContr
{
if (!_searchBarDisplayContr) {
_searchBarDisplayContr = [[UISearchDisplayController alloc] initWithSearchBar:self.searchBar contentsController:self];
_searchBarDisplayContr.delegate = self;
_searchBarDisplayContr.searchResultsDataSource = self.tableView.dataSource;
_searchBarDisplayContr.searchResultsDelegate = self.tableView.delegate;
_searchBarDisplayContr.searchResultsTableView.backgroundColor = [UIColor clearColor];
_searchBarDisplayContr.searchResultsTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}
return _searchBarDisplayContr;
}
- (NSMutableArray *)searchResults
{
if (!_searchResults) {
_searchResults = [NSMutableArray arrayWithCapacity:_restaurants.count];
}
return _searchResults;
}
- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
[self.searchResults removeAllObjects];
[self.restaurants enumerateObjectsUsingBlock:^(Restaurant *restaurant, NSUInteger idx, BOOL *stop) {
if ([scope isEqualToString:#"All"] || [restaurant.name isEqualToString:scope]) {
NSRange range = [restaurant.name rangeOfString:searchText
options:(NSCaseInsensitiveSearch | NSDiacriticInsensitiveSearch)];
if (range.length > 0) {
[self.searchResults addObject:restaurant];
}
}
}];
}
- (BOOL)searchDisplayController:(UISearchDisplayController*)controller shouldReloadTableForSearchString:(NSString*)searchString
{
[self filterContentForSearchText:searchString
scope:#"All"];
dispatch_async(dispatch_get_main_queue(), ^(void) {
for (UIView *v in controller.searchResultsTableView.subviews) {
if ([v isKindOfClass:[UILabel class]]) {
((UILabel *)v).text = kSearchResultsTableViewNoResultsLabel;
((UILabel *)v).font = [UIFont mediumFontOfSize:20.0f];
((UILabel *)v).textColor = [UIColor blackColor];
break;
}
}
});
return YES;
}
- (BOOL)searchDisplayController:(UISearchDisplayController*)controller shouldReloadTableForSearchScope:(NSInteger)searchOption
{
[self filterContentForSearchText:[self.searchBarDisplayContr.searchBar text]
scope:#"All"];
return YES;
}
But for some reason when I search the searchResultsTableView is not updated / cellForRowAtIndexPath is not called. The tableView delegates and DataSource is setup in my storyboard.
Any ideas why this is happening?
UPDATE:
[self.tableView registerClass:[RestaurantsCell class] forCellReuseIdentifier:cellIdentifier];
[self.searchBarDisplayContr.searchResultsTableView registerClass:[RestaurantsCell class] forCellReuseIdentifier:cellIdentifier];
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section
{
if (tableView == self.searchBarDisplayContr.searchResultsTableView) {
return [self.searchResults count];
} else {
return [self.restaurants count];
}
return 0;
}
- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
RestaurantsCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
Restaurant *restaurant;
if (tableView == self.searchBarDisplayContr.searchResultsTableView) {
if (self.searchResults.count > 0) {
restaurant = self.searchResults[indexPath.row];
}
} else {
if (self.restaurants.count > 0) {
restaurant = self.restaurants[indexPath.row];
}
}
if (restaurant) {
cell.titleLabel.text = restaurant.name;
}
return cell;
}
This is the offending line:
RestaurantsCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
Should be:
RestaurantsCell *cell = [self.tableView dequeueReusableCellWithIdentifier:cellIdentifier];
Explanation:
If the tableView turns out to be your search results table view, then trying to dequeue a cell with an identifier won't work because it doesn't have prototype cells. Therefore, you have to use self.tableView
Also, your code can be cleaned up a lot:
- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section
{
return (tableView == self.tableView) ? self.restaurants.count : self.searchResults.count;
}
- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
RestaurantsCell *cell = [self.tableView dequeueReusableCellWithIdentifier:cellIdentifier];
Restaurant *restaurant = (tableView == self.tableView) ? self.restaurants[indexPath.row] ? self.searchResults[indexPath.row];
}
cell.titleLabel.text = restaurant.name;
return cell;
}
Edit
Check out this example
I am using hpple to get data from web page and display it in table view, but i want to cells to display " no data" if there either is no data or it can't get the data. But because of this it flases the no data on the view controller for about a second when the data is loaded here is the code i am using:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
switch (section) {
case 0:
if ((_deli.count > 0)) {
return _deli.count;
}
else {
return 1;
}
break;
case 1:
if ((_entrees.count > 0)) {
return _entrees.count;
}
else {
return 1;
}
break;
}
return 0
}
and then
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
//[UIColor colorWithRed:191.0f/255.0f green:48/255.0f blue:48/255.0f alpha:1.0]
cell.textLabel.textColor = [UIColor whiteColor];
cell.textLabel.font = [UIFont fontWithName:#"TimesNewRomanPS-BoldMT" size:17.0f];
if (indexPath.section == 0) {
if ([tableView numberOfRowsInSection:0] == _deli.count ) {
Items *thisDeli = [_deli objectAtIndex:indexPath.row];
cell.textLabel.text = thisDeli.title;
}
else { cell.textLabel.text = #"No Data Avaiable";
}
}
else if (indexPath.section == 1) {
if ([tableView numberOfRowsInSection:1] == _entrees.count) {
Items *thisEntree = [_entrees objectAtIndex:indexPath.row];
cell.textLabel.text = thisEntree.title;
}
else { cell.textLabel.text = #"No Data Avaiable";
}
}
}
Is there a way to delay the appearance of the "no data" phrase or only display it if it is blank or can't get it.
Heres my NSURLConnection
- (void) loadDataUsingNSURLConnection {
NSString *url = #"http://ueat.site88.net/westTest.xml";
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
NSLog(#"response == %#", response);
}
Thanks for your help in advance.
Cheers
Consider making the "No Data Available" string dynamic based on whether your call has completed to load the data or not. If the call has not completed have it use "Loading" or something like that. If the call has completed have it show the existing "No Data Available" string.
EDIT WITH EXAMPLE:
The easiest thing to do, with the code you have, is to set your _deli and _entrees variables to nil until you've loaded them, and check for that condition when displaying your message:
#interface YourViewController ()
{
NSArray *_deli;
NSArray *_entrees;
}
#end
Set the arrays to nil in your viewDidLoad
- (void)viewDidLoad
{
[super viewDidLoad];
_deli = nil;
_entrees = nil;
}
Change the logic in your previous code to this:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
switch (section) {
case 0:
if (_deli == nil || _deli.count == 0) {
return 1;
}
else {
return _deli.count;
}
break;
case 1:
if (_entrees == nil || _entrees.count == 0) {
return 1;
}
else {
return _entrees.count;
}
break;
}
return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
//[UIColor colorWithRed:191.0f/255.0f green:48/255.0f blue:48/255.0f alpha:1.0]
cell.textLabel.textColor = [UIColor whiteColor];
cell.textLabel.font = [UIFont fontWithName:#"TimesNewRomanPS-BoldMT" size:17.0f];
if (indexPath.section == 0) {
if (_deli == nil)
cell.textLabel.text = #"Loading";
else if (_deli.count > 0) {
Items *thisDeli = [_deli objectAtIndex:indexPath.row];
cell.textLabel.text = thisDeli.title;
}
else
cell.textLabel.text = #"No Data Avaiable";
}
else if (indexPath.section == 1) {
if (_entrees == nil)
cell.textLabel.text = #"Loading";
else if (_entrees.count > 0) {
Items *thisEntree = [_entrees objectAtIndex:indexPath.row];
cell.textLabel.text = thisEntree.title;
}
else
cell.textLabel.text = #"No Data Avaiable";
}
}
Since your loadDataUsingNSURLConnection just writes out the response I'm not sure how you're loading the array, but you should get the idea at this point. All you need to do is just load the response into the array and call the reloadData method on your table to get the new data to appear.