I have a tableview that is blank by default. User can add cells to it.
I want the separator lines to be clear when there are no cells, and grey when there are cells.
I am using this code:
if ([[self.fetchedResultsController fetchedObjects] count] == 0)
{
self.routineTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.routineTableView.separatorColor = [UIColor clearColor];
}
else
{
self.routineTableView.separatorColor = [UIColor grayColor];
}
The problem is, when I launch the app with a blank table, and if I add cells, the grey lines are not there there until I restart the app. But if I start with cells there, then delete them, then re-add them, the lines are there. Any suggestions?
Maybe you are missing this?
EDIT :
You need this but not only this… According to Apple Documentation :
That means the style wont change for cells that are already loaded. Just scrolling the table to force cells to redraw should make separators appearing…
You then have to :
set it BEFORE cell is inserted
OR
reload
tableViewwhen the first cell is addedwhich is not easy to do with a
NSFetchedResultsController, you should look into its delegate for a solution… or change direction, like hiding thetableViewuntil you have a result maybe…EDIT 2 : You can also simply add this :
but that’s a dirty workaround that will just reload full tableView, losing most benefits of
NSFetchedResultsController…