I have a UITableview made up with a custom cell loaded from a nib. This custom cell has 9 UILabel s and thats all. When scrolling the table on my iPhone the tables scrolling motion is slightly jerky, its not as smooth as other tableviews! (On the simulator it scrolls fine but I guess its using the extra power of my mac)
Are there any tips to help optimize this or any tableview or methods to help find the bottleneck.
Many Thanks
UPDATE:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return [[fetchedResultsController sections] count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
id <NSFetchedResultsSectionInfo> sectionInfo = [[fetchedResultsController sections] objectAtIndex:section];
return [sectionInfo numberOfObjects];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
//Returns the title for each section header. Title is the Date.
id <NSFetchedResultsSectionInfo> sectionInfo = [[fetchedResultsController sections] objectAtIndex:section];
NSArray *objects = [sectionInfo objects];
Data *myData = [objects objectAtIndex:0];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateStyle:NSDateFormatterLongStyle];
NSDate *headerDate = (NSDate *)myData.dataDate;
NSString *headerTitle = [formatter stringFromDate:headerDate];
[formatter release];
return headerTitle;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *dataEntryCellIdentifier = @"dataEntryCellIdentifier";
DataEntryCell *cell = (DataEntryCell *)[tableView dequeueReusableCellWithIdentifier:dataEntryCellIdentifier];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"DataEntryCell" owner:self options:nil];
cell = self.dataEntryCell;
self.dataEntryCell = nil;
}
[self configureCell:cell atIndexPath:indexPath];
return cell;
}
//Method to setup the labels in the cell with managed object content.
- (void)configureCell:(DataEntryCell *)cell atIndexPath:(NSIndexPath *)indexPath {
Data *myData = [fetchedResultsController objectAtIndexPath:indexPath];
cell.label1.text = myData.data1;
cell.label2.text = myData.data2;
cell.label3.text = myData.data3;
cell.label4.text = myData.data4;
cell.label5.text = myData.data5;
cell.label6.text = myData.data6;
}
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
//Check to see if its in Delete mode
if (editingStyle == UITableViewCellEditingStyleDelete) {
//Delete Object from context.
NSManagedObjectContext *context = [fetchedResultsController managedObjectContext];
[context deleteObject:[fetchedResultsController objectAtIndexPath:indexPath]];
//Save Context to persitant store
NSError *error = nil;
if (![context save:&error]) {
NSLog(@"Delete Error");
exit(-1);
}
}
}
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
// Table is not to be manually reordered
return NO;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//Create a detailView instance.
DetailViewController *detailView = [[DetailViewController alloc] initWithStyle:UITableViewStyleGrouped];
//Pass selected data to the detailView.
Data *myData = [fetchedResultsController objectAtIndexPath:indexPath];
detailView.myData = myData;
//Push the detailView onto the Nav stack.
[self.navigationController pushViewController:detailView animated:YES];
[detailView release];
}