Оптимизация UITableView - PullRequest
       2

Оптимизация UITableView

1 голос
/ 22 апреля 2010

У меня есть UITableview с пользовательской ячейкой, загруженной из пера.Эта пользовательская ячейка имеет 9 UILabel s и это все.При прокрутке таблицы на моем iPhone движение прокрутки таблиц слегка прерывистое, не такое плавное, как у других видов таблиц!(На симуляторе он прекрасно прокручивается, но я предполагаю, что он использует дополнительную мощность моего mac)

Есть ли какие-либо советы, которые помогут оптимизировать этот или любой вид таблицы или методы, помогающие найти узкое место.Большое спасибо

ОБНОВЛЕНИЕ:

- (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];
}

1 Ответ

4 голосов
/ 22 апреля 2010

Взгляните на этот вопрос , на который ссылается автор Tweetie. Короче говоря: делайте свой рисунок вручную, не используя подпредставления.

Оригинальную статью о Tweetie теперь можно найти здесь .

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...