Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/104.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 动态单元格高度和首选内容大小_Ios_Uitableview_Uipopovercontroller - Fatal编程技术网

Ios 动态单元格高度和首选内容大小

Ios 动态单元格高度和首选内容大小,ios,uitableview,uipopovercontroller,Ios,Uitableview,Uipopovercontroller,我使用算法在单元格中有一个多行标签。我想在popover中显示表视图。因此,我将preferredContentSize设置为类似于viewdide中的设置 但是如果我查询tableview的contentSize,我会得到错误的高度。尽管我的最后一个单元格具有动态高度(取决于多行标签中的文本),但它似乎始终采用默认的行高度(44f) 我注意到的是,在计算完所有单元格的高度之前,会调用viewdideappear。这是什么意思?以下是在heightforrowatinexpath中查询的索引路径

我使用算法在单元格中有一个多行标签。我想在popover中显示表视图。因此,我将
preferredContentSize
设置为类似于
viewdide
中的设置

但是如果我查询tableview的
contentSize
,我会得到错误的高度。尽管我的最后一个单元格具有动态高度(取决于多行标签中的文本),但它似乎始终采用默认的行高度(44f)

我注意到的是,在计算完所有单元格的高度之前,会调用
viewdideappear
。这是什么意思?以下是在
heightforrowatinexpath
中查询的索引路径摘录:

2015-11-13 14:49:20.592 [53865:2230330] Default: <NSIndexPath: 0x7eb27130> {length = 2, path = 0 - 0}
2015-11-13 14:49:20.594 [53865:2230330] Default: <NSIndexPath: 0x7e904750> {length = 2, path = 0 - 1}
2015-11-13 14:49:20.595 [53865:2230330] Default: <NSIndexPath: 0x7e9f7730> {length = 2, path = 0 - 2}
2015-11-13 14:49:20.596 [53865:2230330] Default: <NSIndexPath: 0x7e9fbd60> {length = 2, path = 0 - 3}
2015-11-13 14:49:20.596 [53865:2230330] Default: <NSIndexPath: 0x7e91bee0> {length = 2, path = 1 - 0}
2015-11-13 14:49:20.597 [53865:2230330] Default: <NSIndexPath: 0x7e90bde0> {length = 2, path = 1 - 1}
2015-11-13 14:49:20.598 [53865:2230330] Default: <NSIndexPath: 0x7e9081e0> {length = 2, path = 1 - 2}
2015-11-13 14:49:20.599 [53865:2230330] Default: <NSIndexPath: 0x7e902d30> {length = 2, path = 1 - 3}
2015-11-13 14:49:20.599 [53865:2230330] Default: <NSIndexPath: 0x7e900b10> {length = 2, path = 1 - 4}
2015-11-13 14:49:20.600 [53865:2230330] Default: <NSIndexPath: 0x7ec24470> {length = 2, path = 0 - 0}
2015-11-13 14:49:20.601 [53865:2230330] Default: <NSIndexPath: 0x7ec24590> {length = 2, path = 0 - 1}
2015-11-13 14:49:20.601 [53865:2230330] Default: <NSIndexPath: 0x7ec24570> {length = 2, path = 0 - 2}
2015-11-13 14:49:20.601 [53865:2230330] Default: <NSIndexPath: 0x7ec24580> {length = 2, path = 0 - 3}
2015-11-13 14:49:20.601 [53865:2230330] Default: <NSIndexPath: 0x7ec24a60> {length = 2, path = 1 - 0}
2015-11-13 14:49:20.601 [53865:2230330] Default: <NSIndexPath: 0x7ec24bf0> {length = 2, path = 1 - 1}
2015-11-13 14:49:20.602 [53865:2230330] Default: <NSIndexPath: 0x7ec24d80> {length = 2, path = 1 - 2}
2015-11-13 14:49:20.602 [53865:2230330] Default: <NSIndexPath: 0x7ec24f10> {length = 2, path = 1 - 3}
2015-11-13 14:49:20.602 [53865:2230330] Default: <NSIndexPath: 0x7ec250a0> {length = 2, path = 1 - 4}
// viewDidAppear is called setting the preferredContentSize
2015-11-13 14:49:31.374 [53865:2230330] Default: <NSIndexPath: 0x7e80fb20> {length = 2, path = 2 - 0}
2015-11-13 14:49:31.378 [53865:2230330] Adaptive: <NSIndexPath: 0x7e9088b0> {length = 2, path = 3 - 0}
2015-11-13 14:49:31.379 [53865:2230330] Default: <NSIndexPath: 0x7ec231c0> {length = 2, path = 2 - 0}
2015-11-13 14:49:20.592[53865:2230330]默认值:{length=2,path=0-0}
2015-11-13 14:49:20.594[53865:2230330]默认值:{length=2,path=0-1}
2015-11-13 14:49:20.595[53865:2230330]默认值:{length=2,path=0-2}
2015-11-13 14:49:20.596[53865:2230330]默认值:{length=2,path=0-3}
2015-11-13 14:49:20.596[53865:2230330]默认值:{length=2,path=1-0}
2015-11-13 14:49:20.597[53865:2230330]默认值:{length=2,path=1-1}
2015-11-13 14:49:20.598[53865:2230330]默认值:{length=2,path=1-2}
2015-11-13 14:49:20.599[53865:2230330]默认值:{length=2,path=1-3}
2015-11-13 14:49:20.599[53865:2230330]默认值:{length=2,path=1-4}
2015-11-13 14:49:20.600[53865:2230330]默认值:{length=2,path=0-0}
2015-11-13 14:49:20.601[53865:2230330]默认值:{length=2,path=0-1}
2015-11-13 14:49:20.601[53865:2230330]默认值:{length=2,path=0-2}
2015-11-13 14:49:20.601[53865:2230330]默认值:{length=2,path=0-3}
2015-11-13 14:49:20.601[53865:2230330]默认值:{length=2,path=1-0}
2015-11-13 14:49:20.601[53865:2230330]默认值:{length=2,path=1-1}
2015-11-13 14:49:20.602[53865:2230330]默认值:{length=2,path=1-2}
2015-11-13 14:49:20.602[53865:2230330]默认值:{length=2,path=1-3}
2015-11-13 14:49:20.602[53865:2230330]默认值:{length=2,path=1-4}
//设置preferredContentSize称为ViewDidDisplay
2015-11-13 14:49:31.374[53865:2230330]默认值:{length=2,path=2-0}
2015-11-13 14:49:31.378[53865:2230330]自适应:{length=2,path=3-0}
2015-11-13 14:49:31.379[53865:2230330]默认值:{length=2,path=2-0}

我如何设置正确的
首选内容大小

我不知道为什么,但似乎
估计的权重对索引路径
有影响

如果我得到动态单元格的索引路径,我会计算单元格高度,并将其用于估计。我的C#代码如下所示:

public override nfloat EstimatedHeight(UITableView tableView, NSIndexPath indexPath)
{
    if (indexPath.Section == 3)
    {
        return this.GetHeightForRow(tableView, indexPath);
    }

    return UITableView.AutomaticDimension;
}
这似乎有效,但我仍然认为这是一种黑客行为