Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/111.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 在我实现'estimatedHeightForRowAt indexPath'后UITableView崩溃? func tableView(tableView:UITableView,estimatedHeightForRowAt indexath:indexPath)->CGFloat{ 让cellHeight=self.promotionListViewList[indexPath.row].tableViewHeight.value 如果单元高度CGFloat{ 让cellHeight=self.promotionListViewList[indexPath.row].tableViewHeight.value 如果单元高度_Ios_Swift_Uitableview - Fatal编程技术网

Ios 在我实现'estimatedHeightForRowAt indexPath'后UITableView崩溃? func tableView(tableView:UITableView,estimatedHeightForRowAt indexath:indexPath)->CGFloat{ 让cellHeight=self.promotionListViewList[indexPath.row].tableViewHeight.value 如果单元高度CGFloat{ 让cellHeight=self.promotionListViewList[indexPath.row].tableViewHeight.value 如果单元高度

Ios 在我实现'estimatedHeightForRowAt indexPath'后UITableView崩溃? func tableView(tableView:UITableView,estimatedHeightForRowAt indexath:indexPath)->CGFloat{ 让cellHeight=self.promotionListViewList[indexPath.row].tableViewHeight.value 如果单元高度CGFloat{ 让cellHeight=self.promotionListViewList[indexPath.row].tableViewHeight.value 如果单元高度,ios,swift,uitableview,Ios,Swift,Uitableview,当我取消对该方法的注释并在iPhone5或iPad2上运行我的项目时,我遇到了以下异常: func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat { let cellHeight = self.promotionListViewList[indexPath.row].tableViewHeight.value return max(ce

当我取消对该方法的注释并在iPhone5或iPad2上运行我的项目时,我遇到了以下异常:

func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
    let cellHeight = self.promotionListViewList[indexPath.row].tableViewHeight.value
    return max(cellHeight, 1.0)
}
“表视图行高度不能为负值-为索引路径提供的高度”

应用程序崩溃了

但是为什么呢

我在这个方法中没有产生负值

如果我对它进行评论,什么也不会发生。

请尝试以下方法:

func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
    let cellHeight = self.promotionListViewList[indexPath.row].tableViewHeight.value
    if cellHeight < 0 {
        return 1.0
    } else {
        return cellHeight
    } 
}

如果您根据本节使用自动布局,请回答:

  • 估计1.0的行高会导致异常:“NSInternalInconsistencyException”,原因:“表视图行高不能为负…”

  • 估计值小于1.0也有奇怪的结果

  • 在2.0和实际值之间进行估算没有任何例外(尽管出于优化原因,2.0可能是一个不好的选择-您希望尽可能接近实际值)

  • 仅当估计行高大于实际行高时,才会发生约束异常。越接近实际情况,异常发生的可能性就越小。在获得异常之前,您的估计距离有多远似乎与几个不同的因素有关:实际行高、行位置等

  • 此解决方案应避免以下例外情况:

    func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
        let cellHeight = self.promotionListViewList[indexPath.row].tableViewHeight.value
        return max(cellHeight, 1.0)
    }
    
    func tableView(tableView:UITableView,estimatedHeightForRowAt indexath:indexPath)->CGFloat{
    让cellHeight=self.promotionListViewList[indexPath.row].tableViewHeight.value
    如果单元高度<0{
    返回1.01
    }否则{
    返回高度
    } 
    }
    
    是否使用自动布局?如果不返回显式值
    1.0
    ,您只需使用
    UITableViewAutomaticDimension
    ,谢谢大家。我不使用自动布局。我不喜欢
    UITableViewAutomaticDimension
    ,因为我已经有了计算单元格高度的逻辑…首先谢谢你,我以前看过这个链接。我稍后再试!谢谢,但是这个代码和我的代码看起来没什么不同