UITableView& UICollectionView性能优化

时间:2016-02-26 08:53:34

标签: ios objective-c performance uitableview uicollectionview

你好同事Apple开发者!

我正在为iPhone和iPhone创建一个iOS应用程序。 iPad兼容。 UITableViewUICollectionView效果是我的应用程序中非常重要的功能。

经过长时间的优化,人眼在滚动发生时无法区分。虽然,分析器仍然会发现一些问题。

  1. 第一个效率低下的东西是出列。我有一个UITableViewCell对象,该用户界面是使用 .xib 文件和自动布局约束创建的。尽管如此,时间分析仪器会在将这个特定单元格出列时抱怨性能。
  2. enter image description here

    1. 我无法理解的另一个问题是将NSString设置为UILabel的文字。此setter方法在方法- tableView:cellForRowAtIndexPath:中执行。
    2. enter image description here

      1. 可能与之前的问题相关的另一个问题是UIImage设置为UIImageView的图像。此方法也在方法- tableView:cellForRowAtIndexPath:中执行,并且不会触发任何下载等。
      2. enter image description here

        如上所述,

        UITableViewCell个对象是默认大小&真的很简单。单元格的内容视图仅包含2个子视图:UILabelUIImageView

        根据Apple的示例下载图片。

        // Asks the data source for a cell to insert in a particular location of the table view.
        - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
        {
            // Dequeues & initializes category table view cell.
            CategoryTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CategoryTableViewCellIdentifier];
        
            APICategory *category = [self.categories objectAtIndex:indexPath.row];
        
            if (category.thumbnail)
            {
                [cell updateThumbnailWithCategory:category];
            }
        
            else
            {
                if (!tableView.dragging && !tableView.decelerating)
                {
                    [category thumbnailWithSuccess:^(UIImage *thumbnail)
                    {
                        if ([tableView.visibleCells containsObject:cell])
                        {
                            [cell updateThumbnailWithCategory:category];
                        }
                    }
        
                    failure:^(NSError *error)
                    {
                        // Handle thumbnail receive failure here!
                    }];
                }
        
                [cell updateThumbnailWithPlaceholder];
            }
        
            cell.category = [self.categories objectAtIndex:indexPath.row];
        
            return cell;
        }
        

        在这种情况下使用的特定图像是.png图像 300x300 分辨率和24 kb大小。

        这些是与UITableViewUICollectionView效果相关的问题。

        任何人都可以解释一下,这些问题可能是什么原因?

        另外,有没有办法改进它?

0 个答案:

没有答案