断言失败 - [UITableView _classicHeightForRowAtIndexPath:],

时间:2016-10-10 09:14:42

标签: ios uitableview

hideCellConst变量计算隐藏所有视图高度并返回tableview单元格的高度。但是它给出了上面的错误。

创建此自定义单元格。我想计算所有隐藏视图高度常量值,并根据显示视图常量返回单元格的高度

class View_Partner_Pref_Cell:UITableViewCell{



 @IBOutlet var viewHeightImage: NSLayoutConstraint!

    @IBOutlet var viewHeightHideAll: NSLayoutConstraint!

    @IBOutlet var lblDetails1: UILabel!
    @IBOutlet var lblDetails2: UILabel!
    @IBOutlet var lblDetails3: UILabel!
    @IBOutlet var lblDetails4: UILabel!


    @IBOutlet var view1: UIView!
    @IBOutlet var view2: UIView!
    @IBOutlet var view3: UIView!

    @IBOutlet var viewHeight1: NSLayoutConstraint!
    @IBOutlet var viewHeight2: NSLayoutConstraint!
    @IBOutlet var viewHeight3: NSLayoutConstraint!
    @IBOutlet var viewHeight4: NSLayoutConstraint!
  }





 func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
        if indexPath.section == 8{

                        return 455 - hideCellConst
                    }

        }
      func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
    if indexPath.section == 8 {
     let cell = tableView.dequeueReusableCellWithIdentifier("partnerPrefCell") as! View_Partner_Pref_Cell

                    let pModel = partnerPrefArray.objectAtIndex(indexPath.row) as! PartnerPreferencesModel
      if pModel.age == ""{
                        cell.view1.hidden = true
                        hideCellConst += cell.viewHeight1.constant
                        cell.viewHeight1.constant = 0
                    }else{
                        cell.view1.hidden = false
                        cell.viewHeight1.constant = 25
                        cell.lblDetails1.text = "Age: \(pModel.age)"
                    }
                    if pModel.height == ""{
                        cell.view2.hidden = true
                        hideCellConst += cell.viewHeight2.constant
                        cell.viewHeight2.constant = 0
                    }else{
                        cell.view2.hidden = false
                        cell.viewHeight2.constant = 25
                        cell.lblDetails2.text = "Height: \(pModel.height)"
                    }
                    if pModel.body_type == ""{
                        cell.view3.hidden = true
                         hideCellConst += cell.viewHeight3.constant
                        cell.viewHeight3.constant = 0
                    }else{
                        cell.view3.hidden = false
                        cell.viewHeight3.constant = 25
                        cell.lblDetails3.text = "Body Type: \(pModel.body_type)"
                    }
                    if pModel.marital_status == ""{
                        cell.view4.hidden = true
                         hideCellConst += cell.viewHeight4.constant
                        cell.viewHeight4.constant = 0
                    }else{
                        cell.view4.hidden = false
                        cell.viewHeight4.constant = 25
                        cell.lblDetails4.text = "Marital Status: \(pModel.marital_status)"
                    }
             return cell
    }
     return cell
    }

1 个答案:

答案 0 :(得分:0)

@ user7301096评论是正确的解决方案。您的逻辑可能是正确的,但是如果计算出的rowHeight小于0,您将获得此异常。这里的简单修复是在小于的情况下返回零。