I have a refresh button in the toolbar that regenerates an NSArray
and attempts to reload the contents of the table.
However, whether I have:
if (boolCondition) {
[self refreshTableDataSet];
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:kTableSectionOfInterest] withRowAnimation:UITableViewRowAnimationFade];
}
or:
if (boolCondition) {
[self refreshTableDataSet];
[self.tableView reloadData];
}
About every other attempt to refresh the table fails. Sometimes it works, sometimes not.
I have some NSLog
statements in -tableView:cellForRowAtIndexPath:
to let me know when this method is being fired. When the refresh fails, I do not see the output of these NSLog
statements.
Is there something I'm missing about reloading a table view, when I have new data?
EDIT
In my -refreshTableDataSet
method:
- (void) refreshTableDataSet {
NSSortDescriptor *_objectTypeSorter = [[[NSSortDescriptor alloc] initWithKey:@"object.type" ascending:YES] autorelease];
NSSet *_objectSet = [managedObjectContext fetchObjectsForEntityName:@"Object" withPredicate:[NSPredicate predicateWithFormat:[NSString stringWithFormat:@"group.name like '%@'", [group name]]]];
self.objects = [[[_objectSet allObjects] sortedArrayUsingDescriptors:[NSArray arrayWithObjects: _objectTypeSorter, nil]] retain];
}
In my table view -tableView:cellForRowAtIndexPath:
method:
...
Object *_object = [self.objects objectAtIndex:indexPath.row];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text = _object.name;
cell.detailTextLabel.text = _object.type;
cell.imageView.image = [UIImage imageNamed:@"GroupType.png"];
cell.accessoryView = [self imageViewForObjectDetailType:_object.type];
...
I have a method for the accessoryView called -imageViewForObjectDetailType
, which just returns a UIImageView
:
return [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"GenericObjectDetailType.png"]] autorelease];
Are there retain
and/or release
messages that I am missing?