【发布时间】:2017-01-20 22:28:12
【问题描述】:
我有一个函数可以创建一个数组UIStackViews,其中包含UIButtons:
func generateStackViews() -> [UIStackView] {
var stackViewArray = [UIStackView]()
let finalButtonArray = generateButtons()
for buttons in finalButtonArray{
stackViewArray.append(createStackView(subViews: buttons))
}
return stackViewArray
}
然后我将该数组添加到 tableViewCell:
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "First")!
cell.contentView.addSubview(generateStackViews()[indexPath.row])
return cell
}
一切正常,但是当我尝试添加约束以将 stackViews 固定到单元格时,我收到此错误:
失败 -[UITableViewCell _layoutEngine_didAddLayoutConstraint:roundingAdjustment:mutuallyExclusiveConstraints:]
我尝试在创建stackViews 的函数和cellForRowAt 函数中添加约束,尝试将其固定到contentView、单元格和tableView,但都不起作用,我得到了同样的错误消息。
我的逻辑哪里出错了?
【问题讨论】:
标签: ios swift uitableview ios-autolayout uistackview