如果未声明 heightForRowAtIndexPath,iOS 7.1 崩溃
Posted
技术标签:
【中文标题】如果未声明 heightForRowAtIndexPath,iOS 7.1 崩溃【英文标题】:iOS 7.1 crash if heightForRowAtIndexPath is not declared 【发布时间】:2015-03-10 08:05:00 【问题描述】:我试图使用 estimatedHeightForRowAtIndexPath
来实现具有 AutoLayout 的动态单元格高度,并在 ios8 中按预期工作,但在 iOS7.1 中这样说:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MyProject.ViewController tableView:heightForRowAtIndexPath:]: unrecognized selector sent to instance 0x79e91350'
如果我定义heightForRowAtIndexPath
,错误就会消失,但单元格不会自动调整大小。有什么想法吗?
更新:它确实在 iOS 7.0 中可用,对吧?
【问题讨论】:
【参考方案1】:试试:
if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1 )
self.tableView.rowHeight = UITableViewAutomaticDimension;
self.tableView.estimatedRowHeight = 206;
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
if NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1
return UITableViewAutomaticDimension
else return 206
【讨论】:
不会在 heightForRowAtIndexPath 中传递显式值:违反实现动态单元格高度概念的核心思想?我有一个类似的问题,我无法弄清楚 - 请参阅***.com/questions/29425782/…以上是关于如果未声明 heightForRowAtIndexPath,iOS 7.1 崩溃的主要内容,如果未能解决你的问题,请参考以下文章
使用 DLL 时 Qt 应用程序崩溃,如果导出的函数未声明 APIENTRY,则可以正常工作
让 UITableViewCell 使用自动布局调整自身大小
C 2065 AFX_IDW_MENUBAR未声明的标识符 错误提示