Swift : 如何从代码中删除插座?

Swift :How can i remove the outlets from code?

我有一个视图的高度插座。它被设置为55.In一个我用过的tableview。有些地方我需要静态高度,有些地方不需要高度。所以我想从我的code.How中删除这个静态高度我可以实现吗?这可能吗?

func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
        if(heightIsStatic.count> 0)
        {
     //here i require a static height and is working fine as height can   
     //be printed as 55
        }
        else
        {
            self.ViewHeight.active = false
            print(self.ViewHeight.constant)
        }
    }

即使我已将 active 设置为 false,它仍然显示静态高度 constraint.Can 在其他情况下我删除了静态高度??

如果你想要 else 部分的动态大小,那么你必须删除约束的出口,然后在你的代码中你必须找到约束,然后更改它的常量或在需要时删除

for constraint in view.constraints {
    if(constraint.firstAttribute == NSLayoutAttribute.height)
    {
         constraint.constant = 55
    }
}

如果我正确理解你的问题,请试试这个(假设你的单元格的约束是正确的)

override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
 if (indexPath.row == 1) { //change this with the row number
  return 55.0
 }

 return UITableViewAutomaticDimension
}

如果您没有特定的行,请发表评论,我将编辑我的答案。谢谢!