2012-10-10 20 views
2

解決不同的UITableView滾動性能的iPad 2&iPhone 4S

有所述self.view層上的陰影。刪除它後,表格視圖平滑滾動(56-59fps)。

我得到的問題太奇怪了。

我正在構建一個基於UITableView的Twitter應用程序。在優化了表格視圖加載和滾動之後,我在iPad 2和iPhone 4S上測試了應用程序(相同的代碼&相同的用戶界面)。在iPad 2上,我有56-59fps的平滑滾動動畫。但在iPhone 4S上,我只有43-49fps的滾動動畫,這很糟糕。

這似乎不是由視網膜顯示引起的。從單元格中刪除所有圖像後,問題仍然存在。以下是cellForRowAtIndexPath的代碼

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    // fetch note from the fetched results controller 
    Note *note = [self.fetchedResultsController objectAtIndexPath:indexPath]; 

    if ([note.photos count] > 0) { 

     static NSString *CellIdentifier = @"Photo Cell"; 
     PhotoCell *cell = (PhotoCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

     if (cell == nil){ 
      cell = [[PhotoCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
     } else { 
      [cell clearContents]; 
     } 

     NSNumber *currentRowNumber = [NSNumber numberWithInt:indexPath.row]; 
     // check if the photos of this cell has been pre loaded 
     NSDictionary *coverImages = [self.coverImagesForNotes objectForKey:currentRowNumber]; 

     if (coverImages == nil) { 
      if (self.tableView.dragging == NO && self.tableView.decelerating == NO) { 
       coverImages = [self loadCoverImagesForCell:indexPath photos:note.photos]; 
       [self.coverImagesForNotes setObject:coverImages forKey:currentRowNumber]; 
      } 
     } 

     // assign contents to the cell 
     [self compositeContentView:cell forNote:note rowNumber:indexPath.row]; 

     // refine 
     unsigned textContentHeight = [[self.cellTextHeightDict objectForKey:currentRowNumber] integerValue]; 
     unsigned currentPageNumber = [self currentPageNumberAtRow:indexPath.row]; 
     [cell initPhotoVideoView:textContentHeight photos:note.photos coverImages:coverImages showPage:currentPageNumber rowNumber:indexPath.row]; 

     cell.delegate = self; 

     return cell; 

    } else { 
     static NSString *CellIdentifier = @"Simple Cell"; 
     BaseCell *cell = (BaseCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

     if (cell == nil){ 
      cell = [[OneViewBaseCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
     } 

     // assign contents to the cell 
     [self compositeContentView:cell forNote:note rowNumber:indexPath.row]; 

     return cell; 
    } 
} 

感謝您的回答。

+0

感謝您的諮詢! –

回答

1

您在表格視圖單元格中使用圖像嗎?在視網膜顯示器上這將更加昂貴。此外,如果您正在使用圖像,請嘗試將它們加載到後臺線程上,以減少延遲。

如果你不使用的圖像,那麼你真的應該看看你是如何創造你的細胞,請上傳tableView:cellForRowAtIndexPath:方法實現