iOS 7.1 crash if heightForRowAtIndexPath is not declared

戏子无情 提交于 2019-12-10 18:36:19

问题


I was trying to use estimatedHeightForRowAtIndexPath for dynamic cell height with AutoLayout and working as expected in iOS8 but crush in iOS7.1 by saying this:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MyProject.ViewController tableView:heightForRowAtIndexPath:]: unrecognized selector sent to instance 0x79e91350'

If I define heightForRowAtIndexPath, error go away but cell won't auto size itself. Any idea?

Update: It's indeed available in iOS 7.0, right?


回答1:


try :

 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}
    }


来源:https://stackoverflow.com/questions/28958707/ios-7-1-crash-if-heightforrowatindexpath-is-not-declared

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!