【问题标题】:iOS 7.1 crash if heightForRowAtIndexPath is not declared如果未声明 heightForRowAtIndexPath,iOS 7.1 崩溃
【发布时间】: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 中可用,对吧?

【问题讨论】:

    标签: uitableview ios7 autolayout ios7.1


    【解决方案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 中传递显式值:违反实现动态单元格高度概念的核心思想?我有一个类似的问题,我无法弄清楚 - 请参阅stackoverflow.com/questions/29425782/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-04-19
    • 2014-12-13
    • 1970-01-01
    • 1970-01-01
    • 2023-03-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多