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

问题描述:

我有一个视图的高度出口。它被设置为55.在我使用过的tableview中。有些地方我需要静态高度,有些地方不需要高度。所以我想从我的代码中移除这个静态高度。我可以如何实现这一目标?有可能吗?Swift:我如何从代码中删除插座?

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

即使我已设置活跃为false,仍呈现静态高度constraint.Can我删除,在其他情况下,静态的高度?

+0

'ViewHeight.constant = 65 // StaticValue'这样做。 –

+0

我知道吗?我在问我如何删除这个约束,以便它不适用于其他条件。 –

+0

欲了解更多的问题,你可以告诉我你的屏幕图像。 –

如果你想为其他部分,那么你必须删除约束的出口,然后在代码中动态大小,你必须找到约束,然后改变它的恒定或者如果有必要

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

不能分配属性。关系是只获取属性..? –

+0

编辑我的答案请检查 –

+0

@ jennysam它解决了你的问题吗?让我们知道你是否有任何问题。 –

如果我的理解中删除你的问题正确,请,如果你没有一个特定的行试试这个(假设约束你的细胞是正确的)

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

return UITableViewAutomaticDimension 
} 

请评论,我会编辑我的答案。谢谢!

+0

这实际上不是我问什么:) :) :)其而不是关于特定的行 –