2017-10-05 74 views
1

我有一個視圖的高度出口。它被設置爲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

欲瞭解更多的問題,你可以告訴我你的屏幕圖像。 –

回答

2

如果你想爲其他部分,那麼你必須刪除約束的出口,然後在代碼中動態大小,你必須找到約束,然後改變它的恆定或者如果有必要

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

不能分配屬性。關係是隻獲取屬性..? –

+0

編輯我的答案請檢查 –

+0

@ jennysam它解決了你的問題嗎?讓我們知道你是否有任何問題。 –

0

如果我的理解中刪除你的問題正確,請,如果你沒有一個特定的行試試這個(假設約束你的細胞是正確的)

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

這實際上不是我問什麼:) :) :)其而不是關於特定的行 –