簡體   English   中英

斯威夫特:我如何從代碼中刪除網點?

[英]Swift :How can i remove the outlets from code?

我有一個供查看的高度插座。 它設置為55.tableview我已經使用它。 有些在我需要靜態高度的地方,有些在不需要高度的地方。 所以我想從我的代碼中刪除此靜態高度。我怎么能做到這一點?

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,它仍然顯示靜態高度限制。在其他情況下,我可以刪除該靜態高度嗎?

如果您想要其他部分的動態大小,則必須刪除約束的出口,然后在代碼中必須找到約束,然后更改其常量或根據需要刪除

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
}

如果您沒有特定的行,請發表評論,我將編輯我的答案。 謝謝!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM