I have a tableView
in which there is a section that is editable.
If I enable editing on the entire tableView
, other cells while in editing mode are not selectable
, so I need to enable the editing mode only on a specific section so that while other cells are selectable
, the section is editable.
The reason that I need to set editing is those red square minus buttons that appear next to deletable
cells.
Summary:
I need those red minus buttons next to cells, so I need to set editing as true, but if I do so, other cells won't be selectable
thus I need to either set editing as true for a specific section, or add those red minus buttons without the editing mode.
You can implement canEditRowAtIndexPath
method something like,
Obj-C
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 1) {
return YES;
}
return NO;
}
Swift :
func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
if indexPath.section == 1 {
return true
}
return false
}
To enable selection during editing you need to set,
Obj-C
self.yourTableView.allowsSelectionDuringEditing = YES;
Swift
self.yourTableView.allowsSelectionDuringEditing = true
Swift 4/5
override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
if indexPath.section == 1 {
return true
}
return false
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With