从我的理解中,将UITableViewControllers中的可重用单元出列的主要好处是通过仅将当前可见单元及其内容保存在内存中来节省内存。正确地重复使用UITableViewCells和自定义高度
这就是说,它似乎是有道理的每一个细胞被请求的cellForRowAtIndexPath内(分别为GetCell()在MonoTouch的),并释放了整个小区时不使用/可见的再一次创建一个单元格的内容。
如果所有单元具有相同的高度,则工作正常。但是,如果只有一个单元格具有另一个动态高度(通过创建内容视图计算),则高度必须设置在heightForRowAtIndexPath(分别在MonoTouch中为GetHeightForRow())。
现在我感到困惑,因为heightForRowAtIndexPath似乎要调用表中的所有单元格,即使当前不在viewport中的单元格也是如此。
请参阅下面的日志(第一个数字是部分指标,二是行索引):
2013-12-12 13:00:29.322 MyApp[32603:80b] GetHeightForRow - 1 - 0
2013-12-12 13:00:29.323 MyApp[32603:80b] GetHeightForRow - 1 - 1
2013-12-12 13:00:29.323 MyApp[32603:80b] GetHeightForRow - 1 - 2
2013-12-12 13:00:29.323 MyApp[32603:80b] GetHeightForRow - 1 - 3
2013-12-12 13:00:29.324 MyApp[32603:80b] GetHeightForRow - 1 - 4
2013-12-12 13:00:29.324 MyApp[32603:80b] GetHeightForRow - 1 - 5
2013-12-12 13:00:29.325 MyApp[32603:80b] GetHeightForRow - 1 - 6
2013-12-12 13:00:29.325 MyApp[32603:80b] GetHeightForRow - 1 - 7
2013-12-12 13:00:29.326 MyApp[32603:80b] GetHeightForRow - 1 - 8
2013-12-12 13:00:29.326 MyApp[32603:80b] GetHeightForRow - 1 - 9
2013-12-12 13:00:29.326 MyApp[32603:80b] GetHeightForRow - 1 - 10
2013-12-12 13:00:29.327 MyApp[32603:80b] GetHeightForRow - 1 - 11
2013-12-12 13:00:29.327 MyApp[32603:80b] GetHeightForRow - 1 - 12
2013-12-12 13:00:29.328 MyApp[32603:80b] GetHeightForRow - 1 - 13
2013-12-12 13:00:29.328 MyApp[32603:80b] GetHeightForRow - 1 - 14
2013-12-12 13:00:29.329 MyApp[32603:80b] GetHeightForRow - 1 - 15
2013-12-12 13:00:29.329 MyApp[32603:80b] GetHeightForRow - 1 - 16
2013-12-12 13:00:29.330 MyApp[32603:80b] GetHeightForRow - 1 - 17
2013-12-12 13:00:29.330 MyApp[32603:80b] GetHeightForRow - 1 - 18
2013-12-12 13:00:29.330 MyApp[32603:80b] GetHeightForRow - 1 - 19
2013-12-12 13:00:29.331 MyApp[32603:80b] GetHeightForRow - 1 - 20
2013-12-12 13:00:29.331 MyApp[32603:80b] GetHeightForRow - 1 - 21
2013-12-12 13:00:29.331 MyApp[32603:80b] GetHeightForRow - 1 - 22
2013-12-12 13:00:29.332 MyApp[32603:80b] GetHeightForRow - 1 - 23
2013-12-12 13:00:29.332 MyApp[32603:80b] GetHeightForRow - 1 - 24
2013-12-12 13:00:29.332 MyApp[32603:80b] GetHeightForRow - 0 - 0
2013-12-12 13:00:29.333 MyApp[32603:80b] GetHeightForRow - 0 - 1
2013-12-12 13:00:29.335 MyApp[32603:80b] GetCell - 0 - 0
2013-12-12 13:00:29.344 MyApp[32603:80b] GetCell - 0 - 1
2013-12-12 13:00:29.347 MyApp[32603:80b] GetCell - 1 - 0
2013-12-12 13:00:29.349 MyApp[32603:80b] GetCell - 1 - 1
2013-12-12 13:00:29.351 MyApp[32603:80b] GetCell - 1 - 2
2013-12-12 13:00:29.354 MyApp[32603:80b] GetCell - 1 - 3
2013-12-12 13:00:29.356 MyApp[32603:80b] GetCell - 1 - 4
2013-12-12 13:00:29.358 MyApp[32603:80b] GetCell - 1 - 5
2013-12-12 13:00:29.361 MyApp[32603:80b] GetCell - 1 - 6
2013-12-12 13:00:29.363 MyApp[32603:80b] GetCell - 1 - 7
有没有办法来渲染表之前没有创建所有内容的意见,这是我只是看不到?或者,我的基本假设是错误的,那么这将是关于性能的最佳方式,而不是之前创建所有内容视图?
由于
我建议预先计算单元的高度并将它们存储在一个数组中。 – duci9y
如果我愿意,我还需要在显示表格之前创建所有内容视图,因此预期的性能优势将消失。 –
不一定。如果是文本,则可以非常轻松高效地计算大小。 – duci9y