I've currently got a TableViewController with a navigation bar with an editButtonItem. My tableview correctly goes into editing mode when I hit this button, but I want to change the labels on my custom UITableViewCell when isEditing changes. I've tried adding the following into cellForRowAt:
if editingMode {
cell.timeZoneLabel = ""
} else {
cell.timeZoneLabel = timeZone.city
}
But it seems that the tableView isn't reloaded when isEditing changes.
My next thought was to set the following variable at the start:
var editingMode = false {
didSet {
tableView.reloadData()
}
}
And add the following to viewDidLoad() so I can reload the tableView when isEditing changes:
editingMode = isEditing
This doesn't seem to work either though. I've tried searching for other solutions but I can't find anyone having the similar problem.
Any guidance would be much appreciated!
In the cell override didTransition(to
. The rawValue
0 represents normal state, rawValue
1 is showingEditControl
override func didTransition(to state: UITableViewCell.StateMask) {
switch state.rawValue {
case 0: timeZoneLabel = timeZone.city
case 1: timeZoneLabel = ""
default: break
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.