我试图使用此方法获取该 indexPath 的单元格,但出现“EXC_BAD_ACCESS”错误。
但是如果我使用 self.tableView(tableView, cellForRowAtIndexPath:indexPath)
,它工作正常。
我很困惑这两种方法有什么区别?
最佳答案
使用 self.tableView(tableView, cellForRowAtIndexPath:indexPath)
是您的 View Controller 的代码,它出队是一个合适的新单元格。然而,如果单元格不可见, TableView 上的 cellForRowAtIndexPath
方法将返回 nil。由于 heightForRowAtIndexPath
试图找出哪些行是可见的,因此它不起作用也就不足为奇了。
This SO 答案显示在 heightForRowAtIndexPath
中调用 cellForRowAtIndexPath
递归调用自身。这就是您收到错误的原因。
关于ios - 为什么 "tableview.cellForRowAtIndexPath(indexPath)"给我一个 BAD_ACCESS 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35931478/