從我的理解中,將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