Ios 需要为特定的indexath.row设置新约束
我在情节提要中将tableview约束向左和向右设置为零 但取决于我的indexPath.row,我需要设置新的约束(inset&width)。我试过了,但没有成功Ios 需要为特定的indexath.row设置新约束,ios,uitableview,constraints,Ios,Uitableview,Constraints,我在情节提要中将tableview约束向左和向右设置为零 但取决于我的indexPath.row,我需要设置新的约束(inset&width)。我试过了,但没有成功 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { switch dataType! { case .mycase: let c
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
}
}
单元格的框架不会更改,因为它已设置为表的宽度,您可以钩住要移动的项的前导/左&尾/右约束,并根据
cellForRowAt
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
}
func tableView(tableView:UITableView,cellForRowAt indexath:indexPath)->UITableViewCell{
让cell=tableView.dequeueReusableCell(标识符为:“NoBrandDeviceFoundTableViewCell”,用于:indexath)作为!NoBrandDeviceFoundTableViewCell
如果indexPath.row=={
cell.lblLeadingCon.constant=
}
否则{
cell.lblLeadingCon.constant=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