简体   繁体   中英

UITableviewcell delete button apprearing when I swipe right to left on a cell

I have UITableview and I dont need to edit or delete the cells. So requirement is just view only. But when I swipe on a cell a red delete button appears. Please help how can I disable it.

You have a few options depending on your needs. If you don't need any cell editing of any kind then simply add this method:

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    return NO;
}

Editing defaults to YES so you need to turn it off.

IF you need some editing but no deletion then implement:

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
     return UITableViewCellEditingStyleNone;
}

Also, if you don't need either insert or delete, remove the tableView:commitEditingStyle:forRowAtIndexPath: method that may have been added automatically.

Add the following method to your UITableViewDataSource implementation:

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
   return NO;
}

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM