簡體   English   中英

更新約束不適用於UITableView snapkit

[英]Update constraint does not work on UITableView snapkit

當我嘗試在制作約束后立即更新snapkit約束時,我得到了Updated constraint could not find existing matching constraint to update錯誤。 我正在使用的代碼如下:

let directionList = UITableView()
directionList.delegate = self
directionList.dataSource = self
directionList.tag = DIRECTIONS_TABLE_TAG
self.view.addSubview(directionList)
directionList.snp.makeConstraints{ (make) -> Void in
    make.width.equalToSuperview()
    make.top.equalTo(self.view.snp.bottom)
    make.left.equalToSuperview()
    make.right.equalToSuperview()
    make.bottom.equalToSuperview().offset(-20)
}

directionList.snp.updateConstraints { (make) -> Void in
   make.top.equalTo(self.topDarkBlue.snp.bottom)
}

文檔說updateConstraints僅用於更新現有約束的常量。

如果僅更新約束的常數值,則可以使用方法snp.updateConstraints而不是snp.makeConstraints

您沒有更新常量; 您正在嘗試將約束分配給新錨。

我認為您應該做的就是參考最重要的約束條件:

var topConstraint: Constraint? = nil
...
topConstraint = make.top.equalTo(self.view.snp.bottom)

稍后刪除最高約束:

topConstraint.uninstall()

然后使用另一個塊制作新的約束。

directionList.snp.makeConstraints{ (make) -> Void in
   make.top.equalTo(self.topDarkBlue.snp.bottom)
}

暫無
暫無

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

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