可变高度UITableViewCell在滚动到列表末尾并旋转后展开

Pat*_*bee 8 xamarin.ios ios autolayout ios-autolayout

UPDATE

我知道造成这种奇怪的布局错误的原因.它是附件(UITableViewCellAccessory)的设置.如果我停止指定附件,布局不会中断.我没有添加这个作为答案,因为答案需要一个解决方案,给我一个配件,而不打破布局

我看到人们使用动态高度自定义单元格的大部分问题是它们在旋转之前没有正确的高度.但是我看到相反的情况:所有单元格的高度都适用于其动态内容.向上和向下滚动不会破坏这一点.但是,如果我滚动到列表的底部,然后旋转设备,然后向后旋转一行将成为屏幕高度的0.5到1.5倍.

进一步旋转或进一步滚动将使行返回到期望高度.我在屏幕截图之前和之后都包含了几个

滚动前的表格

滚动和旋转后的表格

UITableView的定义如下

this.rootChildrenTable = new UITableView()
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                AccessibilityIdentifier = "rootChildrenTable",
                RowHeight = UITableView.AutomaticDimension,
                EstimatedRowHeight = 44.0f,
                BackgroundColor = UIColor.GroupTableViewBackgroundColor,
                TableFooterView = new UIView(),
                TableHeaderView = this.searchBar,
                KeyboardDismissMode = UIScrollViewKeyboardDismissMode.OnDrag
            };
Run Code Online (Sandbox Code Playgroud)

注意通常的嫌疑人是设置RowHeightEstimatedRowHeight.一旦我Lines = 0从标签中删除,使行的高度相同,问题就会消失.

知道还有什么我应该看的吗?

Vis*_*han 1

我在我的项目中遇到了同样的问题。我通过以下方式设置行的高度克服了这个问题。

\n\n
 //calculate the height by this way\n    override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {\n        return self.heightForBasicCell(at: indexPath)\n    }\n\n\n    func heightForBasicCell(at indexPath: IndexPath) -> CGFloat {\n        var sizingCell: YourCell? = nil\n        var onceToken: dispatch_once_t\n        dispatch_once(onceToken, {() -> Void in\n            sizingCell = tableView.dequeueReusableCell(withIdentifier: YourCell.cellIdentifier())!\n        })\n        self.configureBasicCell(sizingCell, at: indexPath)\n        return self.calculateHeight(forConfiguredSizingCell: sizingCell)\n    }\n\n    func calculateHeight(forConfiguredSizingCell sizingCell: YourCell) -> CGFloat {\n        sizingCell!.bounds = CGRect(x: 0.0, y: 0.0, width: CGRectGetWidth(tableView.frame), height: CGRectGetHeight(sizingCell!.bounds))\n        sizingCell!.setNeedsLayout()\n        sizingCell!.layoutIfNeeded()\n        var size = sizingCell!.contentView.systemLayoutSizeFittingSize(UILayoutFittingCompressedSize)\n        return size.height + 1.0\n        // Add 1.0f for the cell separator height\n    }\n\n    func configureBasicCell(_ cell: YourCell, at indexPath: IndexPath) {\n//set your text here\n    cell(\xe2\x80\x9ctext\xe2\x80\x9d)\n    }\n
Run Code Online (Sandbox Code Playgroud)\n\n

根据您的需要更改代码。我刚刚将 Objective C 代码转换为 swift。

\n