Using the following code:
override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
switch viewControllerCanEdit {
case .viewControllerThatCanNotEdit:
return false
default:
tableView.cellForRow(at: indexPath)?.reuseIdentifier == "CellThatAllowsEditing" else { return false }
return true
}
}
I'm getting the following Assertion Error:
[Assert] Attempted to call -cellForRowAtIndexPath: on the table view while it was in the process of updating its visible cells, which is not allowed. Make a symbolic breakpoint at UITableViewAlertForCellForRowAtIndexPathAccessDuringUpdate to catch this in the debugger and see what caused this to occur. Perhaps you are trying to ask the table view for a cell from inside a table view callback about a specific row? Table view: <UITableView: 0x7fd48303ec00; frame = (0 0; 414 896); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x60000284e070>; layer = <CALayer: 0x60000264f340>; contentOffset: {0, -100}; contentSize: {414, 2765.3333333333335}; adjustedContentInset: {100, 0, 83, 0}; dataSource: <TableViewController: 0x7fd48281b000>>
I've narrowed down the cause. Supposedly this error is a result of the tableView calling canEditRowAt()
while it's in the process of updating the data. And because of that, the call to match the tableView.cellForRow(at:)
doesn't yet exist.
My question is; Is there a way to break out of the function if the tableView is updating? Or if there is a better way of trying to match if the cell can be edited based on the cells type?