本文介绍了iOS UITableViewAutomaticDimension RowHeight性能不佳/跳跃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在iOS 8上构建一个基本的表格视图。我观看了WWDC '14关于自动调整单元格主题的视频,并试图重现这个概念,但是我遇到了一些问题。在viewDidLoad上:我正在打电话:

I'm building a basic table view on iOS 8. I watched the WWDC '14 video on the topic of autosizing cells and am trying to reproduce the concept, but am having some issues. On viewDidLoad: I am calling:

//estimate for my cells though they may vary

self.tableView.estimatedRowHeight = 300.0;

self.tableView.rowHeight = UITableViewAutomaticDimension;

当我的视图和表格加载时,性能还可以。当我单击一个单元格时,程序会将我带到详细视图。当我点击该视图上的后退按钮并返回到表格视图时,那就是事情开始变得怪异的时候。然后,当我滚动时,单元格开始跳跃。通过跳跃我的意思是他们不能顺利滚动 - 他们倾向于从一个地方跳跃或跳跃到下一个地方。

When my view and table load up, performance is ok. When I click on a cell, the program takes me to a detail view. When I hit the back button on that view and return to the table view, that's when things start acting weird. The cells then start 'jumping' while I am scrolling. By jumping I mean that they don't scroll smoothly - they tend to jerk or jump from one place to the next.

我应该补充一点,内存不是问题,因为单元格正在被重用,后台几乎没有数据。我的单元格(在故事板文件中)的约束也是蓝色的,我在调试器中看不到自动布局约束异常。

I should add that memory is not a concern since the cells are being reused and there is little data in the background. The constraints on my cells (in storyboard file) are also blue and I am seeing no autolayout constraint exceptions in the debugger.

有没有其他人看到过这种行为?它只是一个苹果虫还是还有更多呢?谢谢。

Has anyone else seen this kind of behavior with UITableViewAutomaticDimension? Is it just an Apple bug or is there more to it? Thanks.

推荐答案

我发现使用行的奇怪问题self.tableView.rowHeight = UITableViewAutomaticDimension;

然而,当我用委托方法替换它时,一切都变得更好了。在你的情况下将是:

But then, everything came a lot better when I replaced it with the delegates method. In your case would be :

- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return UITableViewAutomaticDimension;
}

- (CGFloat) tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 300.0f;
}

这篇关于iOS UITableViewAutomaticDimension RowHeight性能不佳/跳跃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 23:58