I have a table view with custom cells in it. The cells have some buttons inside of them.
When I press a button to make the table go to editing mode, it doesn't do anything.
If I set the cell's class to UITableViewCell then it works.
The weird thing is that if I set the table view to be in editing mode by default, then when I launch the app the table is in editing mode.
The only problem is when I press the button that is supposed to set it in editing mode.
Edit button:
@objc func didTapEdit(sender: AnyObject){
if table.isEditing == false{
table.isEditing = true
print("okokokok")
} else {
table.isEditing = false
}
}
//This works properly with table views with default cells
Table setup:
view.addSubview(table)
table.translatesAutoresizingMaskIntoConstraints = false
table.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
table.topAnchor.constraint(equalTo: view.topAnchor, constant: navBarHeight).isActive = true
table.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 30).isActive = true
table.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -30).isActive = true
Custom cell:
contentView.addSubview(btn)
btn.translatesAutoresizingMaskIntoConstraints = false
btn.topAnchor.constraint(equalTo: topAnchor, constant: topSpace).isActive = true
btn.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -5).isActive = true
btn.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -5).isActive = true
let btnWidth = NSLayoutConstraint(item: btn, attribute: .width, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 0.0, constant: bounds.height-10)
btn.addConstraint(btnWidth)
I have mutiple buttons which I set up in the same way.
So where's the problem? I created other table views with custom cells and they all worked fine. Plus if I setup the table view to be in editing mode by default, when I run the app it is in editing mode and I can move the cells around! What is going on here? I think the problem might be with how I set the constraints but I have no clue really

