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 如果单元高度
当我取消对该方法的注释并在iPhone5或iPad2上运行我的项目时,我遇到了以下异常: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
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
}
}
如果您根据本节使用自动布局,请回答:
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
,因为我已经有了计算单元格高度的逻辑…首先谢谢你,我以前看过这个链接。我稍后再试!谢谢,但是这个代码和我的代码看起来没什么不同