Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mdhansen5

macrumors member
Original poster
Nov 22, 2010
43
0
Colorado
I'm using Core Data and an NSFetchedResults controller to populate a UITableViewCell (plain style) in my app. The TableView has 3 sections, each with a viewForHeaderInSection and a viewForFooterInSection. The user will be entering items that will be put in each section.

When one of the sections has no items in it, it completely disappears. I'm wondering if it would be possible to make it so if a section is empty, it would display a new cell that would say "no entries" or something like that (maybe with a UIImageView or another view?), which would then go away if a new item was put into that section.

Does anyone know how to accomplish this?

Code:
Data Source Code

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return [[self.fetchedResultsController sections] count];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{    
    return [[[self.fetchedResultsController sections] objectAtIndex:section] numberOfObjects];
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    return [[[self.fetchedResultsController sections] objectAtIndex:section] name];
}

Also, something to point out is that when I delete all the rows from the section, the entire section and it's header goes away as well, and doesn't just show an empty section.
 
Even using NSfetchedResultsController you can still put logic in-between the Tableview and fetchededResults.

I'd start with number of rows for section makes sure it returns 1 if the section is empty. Then the fun bit you then need to make sure not to ask the FetchedResultsController for the item at index. Which will involve a few more of the Tableview methods.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.