【发布时间】:2014-10-27 06:00:17
【问题描述】:
我正在尝试使用此代码将tableView 中每一行的高度设置为相应单元格的高度:
override func tableView(tableView: UITableView!, heightForRowAtIndexPath indexPath: NSIndexPath!) -> CGFloat {
var cell = tableView.cellForRowAtIndexPath(indexPath)
return cell.frame.height
}
初始化var cell 时出现此错误:
线程 1:EXC_BAD_ACCESS(code=2,address=0x306d2c)
【问题讨论】:
-
您不得在
heightForRowAtIndexPath内调用cellForRowAtIndexPath。 EXC_BAD_ACCESS 是由深度递归引起的堆栈溢出引起的。 -
我应该从哪里调用 CellForRowAtIndexPath?
-
heightForRowAtIndexPath必须从数据源计算单元格的高度,而不加载单元格本身。
标签: xcode swift uitableview