Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.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
Swift UITableViewAutomaticDimension-10.0_Swift_Xcode_Uitableviewautomaticdimension - Fatal编程技术网

Swift UITableViewAutomaticDimension-10.0

Swift UITableViewAutomaticDimension-10.0,swift,xcode,uitableviewautomaticdimension,Swift,Xcode,Uitableviewautomaticdimension,我试图将最后一行tableView的高度设置为与其他行不同。 而不是创建一个新的细胞等,我想“削减”从这个细胞的高度10px。因为我已经为高度设置了自动尺寸标注,所以不能使用常量值 这就是它的样子: tableView.estimatedRowHeight = 54.0 return UITableViewAutomaticDimension 我想要这样的东西,但这样不行: if isLastLineBla { tableView.estimatedRowHeight = 44.0

我试图将最后一行tableView的高度设置为与其他行不同。 而不是创建一个新的细胞等,我想“削减”从这个细胞的高度10px。因为我已经为高度设置了自动尺寸标注,所以不能使用常量值

这就是它的样子:

tableView.estimatedRowHeight = 54.0
return UITableViewAutomaticDimension
我想要这样的东西,但这样不行:

if isLastLineBla {
    tableView.estimatedRowHeight = 44.0
    return UITableViewAutomaticDimension-10.0
} else { ...

我希望您有
dataSource
用于
tableView
并在
numberOfRowsAt
方法中返回
dataSource.count

现在执行
heightForRowAt
方法返回正确的值,如下所示:

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    if lastRow {
        return 44
    }else{
        return UITableViewAutomaticDimension
    }
}

不要在每个位置都设置
tableView.estimatedRowHeight=44.0
,您需要设置的唯一位置是
viewDidLoad
方法。

您认为表视图的工作方式遇到了问题。表视图实现了一种延迟加载形式,这样内存中就不会有太多视图

尝试使用表视图委托方法“报告”基于单元格索引的正确高度


你要做的是在你的手机上设置一个标志,叫做isLast或者类似的东西。然后,当从表视图委托返回单元格时,如果它确实是表的最后一个单元格,则应将该标志设置为
true


然后,在单元格上,您应该能够基于该标志修改约束,以便该单元格比其他单元格少10个点。我不能确切地告诉您什么约束以及如何修改它,因为我不知道您的单元格是什么样子。

好的,谢谢。将其设置为44对我不起作用,因为其中有一个标签,其行数/高度可能有所不同。所以我想要UITableViewAutomaticDimension的高度,但是去掉这个高度的10px。这就是我现在正在做的吗?(heightForRowAt delegate)在该方法中,使最后一个单元格10px更小。如果index.row==collection.count-1{return size-10},您不能调用吗?啊,对不起,“isLastLineBla”只是用于缩短代码。这正是我想要做的但问题是,我无法执行以下操作:UITableViewAutomaticDimension-1'NSInternalInconsistencyException',原因:'表委托提供的行高度无效。值必须大于零或UITableViewAutomaticDimension。'UITableViewAutomaticDimension打印为“-1.0”。我指的是约束的外观。我猜左边的标签对您的单元格有底部约束?