在UITableView(iOS8 +)中实现高度可变的单元格的单元格重用 [英] Implementing cell reuse for varying height cells in UITableView (iOS8+)

查看:149
本文介绍了在UITableView(iOS8 +)中实现高度可变的单元格的单元格重用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义单元格布局,继承自MvxTableViewCell.单元格包含的视图之一是支持文本换行的UILabel.包装将意味着单元格可以具有不同的高度,这取决于每个数据项中有多少文本.定义的自定义表格单元格没有任何情节提要或NIB.它使用代码进行布局,并使用AutoLayout.

I have a custom cell layout, inheriting from MvxTableViewCell. One of the cell's contained views is a UILabel that supports text wrapping. The wrapping will mean the cells can be of different heights as that is driven by how much text is in each data item. The custom table cell is defined without any Storyboard or NIB. It is laid out in code and uses AutoLayout.

我发现这些单元正在重复使用,其高度与以前使用时的高度相同.

I am finding that the cells are being reused and the heights are staying the same as they were when they were previously used.

当数据源更新且表中有新项目时,以前较高的单元格将重新用于不需要该额外高度的单元格.我是否需要创建具有特定重用逻辑的自定义MvxTableViewSource?我什至如何确保多余的高度行不会被重复使用?

When the data source is updated and new items are in the table the previously taller cells are reused for cells that don't need that extra height. Do I need to create a custom MvxTableViewSource that has specific reuse logic? How would I even ensure that extra height rows were not reused?

我希望这不是Monotouch和MVVMCross的特定问题,但以防万一,这就是我使用UITableView的方式

I am hoping this is not a Monotouch and MVVMCross specific issue but just in case, this is how I am using the UITableView

this.searchResultsTable = new UITableView();
this.searchResultsTable.AccessibilityIdentifier = "SearchView_SearchResultsTable";
this.searchResultsTable.TranslatesAutoresizingMaskIntoConstraints = false;
this.searchResultsTable.RowHeight = UITableView.AutomaticDimension;
this.searchResultsTable.EstimatedRowHeight = 44.0f;
this.searchResultsTable.AllowsMultipleSelectionDuringEditing = true;
this.searchResultsTable.TableFooterView = new UIView();

第一次使用View时,表格单元格可以正确显示,但随后的使用和滚动一样会引起问题.

The Table Cells display correctly on first use of the View but subsequent uses cause issues as does scrolling.

例如,这是混合高度工作的屏幕截图,在较高的行从屏幕上滚动下来然后重新打开后,后面是相同的列表.红色框显示单元格应该如何放置(FWIW这是测试数据,不是真实的人的数据)

For example here is a screen shot of mixed height working followed by the same list after the taller row has been scrolled off the screen then back on. The red boxes show how box the cell should be (FWIW this is test data not real people's data)

另一个例子,这里再次正确显示表格,然后再次加载相同的数据,但是第二次加载的像元高度不正确

Another example, here the table is again displayed correctly then loaded again with the same data yet the second load has the cell height incorrect

推荐答案

我将我的两个问题分解为两个问题,但是使用这样的答案

I broke my two issues into two questions however there is a solution for both this one and the other issue with this SO answer, UILabel not wrapping in UITableView until device rotate (iOS8)

这篇关于在UITableView(iOS8 +)中实现高度可变的单元格的单元格重用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆