2015年3月11日 星期三

[Xcode] 警告: Detected a case where constraints ambiguously suggest a height of zero for a tableview cell’s content view.

在使用UITableView時,如果有自訂儲存格的高度,要記得另外要設定好rowHeight屬性喔!不然會碰到警告訊息:

Warning once only: Detected a case where constraints ambiguously suggest a height of zero for a tableview cell’s content view. We’re considering the collapse unintentional and using standard height instead.

我這次是載入自訂的儲存格XIB,也有另外設定了rowHeight,忘了妥善處理,所以收到了這個警告,處理的方法很簡單~只要加上這兩個方法~在紅字的地方填上你要的儲存格高度(CGFloat),即可:
func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
        return 你要的儲存格高度
    }
    
    func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
        return 你要的儲存格高度
    }

又或者更簡便的方法是直接在viewDidLoad中加上下述程式碼,即可:
self.tableView.rowHeight = 36.0

參考資料:[Stack Overflow] iOS8 - constraints ambiguously suggest a height of zero: link

沒有留言:

張貼留言