Saturday, November 21, 2026
HomeiOS Developmentios - swift UITableViewCell button constraint not updating to match width on...

ios – swift UITableViewCell button constraint not updating to match width on scroll

[ad_1]

I preserve getting this difficulty with UITableViewCell. After the UITableViewController has loaded, the information has been sorted and the TableView reloaded, I scroll down the record for the primary time and a piece won’t line up with the width of the cell. Every cell has a button with a white background however a few of these buttons defy the constraint set within the cell xib. This trailing constraint will not be touched within the code however for some purpose every time it doesn’t match till you scroll up and down a number of instances.

Button constraint in UITableViewCell not lining up

Constraints of button in xib

I’ve ripped out the code in cellForRowAt to only set the button title (a, b, c, d …) however to no avail.

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "SettingsCell", for: indexPath) as! SettingsCell
    cell.backgroundColor = .clear
    cell.selectionStyle = .none

    cell.cellSwitch.isHidden = true
    
    if (indexPath.part == 0) {
        cell.cellButton.setTitle(sectionTitleA[indexPath.row], for: .regular)            
    }
    
    if (indexPath.part == 1) {
        cell.cellButton.setTitle(sectionTitleB[indexPath.row], for: .regular)           
    }
    
    if (indexPath.part == 2) {
      cell.cellButton.setTitle(sectionTitleC[indexPath.row], for: .regular)    
    } 

    if (indexPath.part == 3) {
        cell.cellButton.setTitle(sectionTitleD[indexPath.row], for: .regular)
    }

    return cell
}

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments