I will try to explain this as best as I can and hope someone can understand what’s going on:
I am using core data to load data into a UITableView. I am trying to add a “last cell” to the end of the TableView to display a logo. Here is my code:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [[self.fetchedResultsController sections] count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
numberOfRows = section;
return [[[self.fetchedResultsController sections] objectAtIndex:numberOfRows] numberOfObjects]+1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[ReminderCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"cellBackground.png"]];
row = indexPath.row;
if (row == [[[self.fetchedResultsController sections] objectAtIndex:numberOfRows] numberOfObjects]) {
NSLog(@"%u",[[[self.fetchedResultsController sections] objectAtIndex:numberOfRows] numberOfObjects]);
cell.productLabel.text = nil;
cell.companyLabel.text = nil;
cell.dateLabel.text = nil;
cell.accessoryType = UITableViewCellAccessoryNone;
cell.logo.hidden = NO;
cell.renewLabel = nil;
}
else {
Reminder *reminder = [self.fetchedResultsController objectAtIndexPath:indexPath];
cell.productLabel.text = reminder.product;
cell.companyLabel.text = reminder.company;
cell.dateLabel.text = reminder.date;
cell.logo.hidden = YES;
}
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
row = [indexPath row];
if (row == [[[self.fetchedResultsController sections] objectAtIndex:numberOfRows] numberOfObjects]) {
return 50;
}
return 78;
}
As you can tell I am telling the last cell to not have an accessory type while all of the other cells are going to have one.
The Normal Cell w/ Accessory Arrow:

Last cell:

Everything works beautifully until I scroll down to the bottom where the last cell is and then scroll back up. The accessory arrow disappears in some of the table cells that are supposed to have it!! (BUT not all of them)
Same Cell but Arrow has disappeared:

What is going on here?
That’s because of the queueing mechanism. The tableView dequeues an arbitrary cell from it’s cache. If that cells happens to be one of those on which you previously set:
it won’t have an accessory indicator. The easiest way to fix that (in my opinion, of course you can also use diffent reuse identifier) is the modify your code like this: