我有一个UITableview,由一个从笔尖加载的自定义单元格组成。这个自定义单元格有9个UILabel,就是这样。当我在我的iPhone上滚动表格时,滚动动作的表格略微不稳定,它不像其他表格一样平滑! (在模拟器上它滚动得很好,但我猜它使用我的mac的额外功率)
是否有任何提示可帮助优化此或任何tableview或方法以帮助找到瓶颈。
非常感谢
更新:
- (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];
}