我在storyboard中将我的tableview约束设置为零左右。
但是取决于我的indexPath.row,我需要设置新的约束(插入和宽度)。我试过这个没有成功。
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
switch dataType! {
case .mycase:
let cell = tableView.dequeueReusableCell(withIdentifier: "NoBrandDeviceFoundTableViewCell", for: indexPath) as! NoBrandDeviceFoundTableViewCell
tableView.isScrollEnabled = false
var frame = tableView.frame
frame.size.width = 343
cell.frame = frame
tableView.contentInset = UIEdgeInsets(top: 0, left: 16, bottom: 0, right: 16)
return cell
}
}
答案 0 :(得分:1)
单元格的框架不会被改变,它被设置为等于桌子的宽度,你可以勾住前导/左边和左边。要转移的项目的尾随/右边约束,并根据func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "NoBrandDeviceFoundTableViewCell", for: indexPath) as! NoBrandDeviceFoundTableViewCell
if indexPath.row == <#someValue#> {
cell.lblLeadingCon.constant = <#someValue#>
}
else {
cell.lblLeadingCon.constant = 0
}
return cell
}
dataType : "jsonp",
答案 1 :(得分:0)
you need to take cell leading constanint - nslcLeadingCell
you need to take cell trailing constatint - nslcTrailningCell
based on indexpathrow contion match you need make condition
if indexpath.row == 5
cell.nslcLeadingCell.constant = 10
cell.nslcTrailningCell.constanct = 15