Sme*_*lap 1 uitableview ios swift 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)
}
| 归档时间: | 
 | 
| 查看次数: | 1836 次 | 
| 最近记录: |