繁体   English   中英

iPad 2和iPhone 4s具有不同的UITableView滚动性能

[英]Different UITableView scrolling performance on iPad 2 & iPhone 4s

解决了

self.view层上有一个阴影。 删除后,表格视图会平滑滚动(56-59fps)。

我遇到的问题太奇怪了。

我正在建立一个基于UITableView的Twitter,例如App。 优化表格视图的加载和滚动后,我在iPad 2和iPhone 4S上测试了该应用程序(相同的代码和相同的UI)。 在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;
    }
}

感谢您的回答。

您是否在表格视图单元格中使用图像? 在视网膜显示器上,这将更加昂贵。 另外,如果您使用的是图像,请尝试将它们加载到后台线程中,这样可以减少延迟。

如果您不使用图像,那么您应该真正了解如何创建单元格,请发布tableView:cellForRowAtIndexPath:方法实现

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM