Is there any way to hide the "-" (Delete) button while editing a UITableView

In my iphone application, I have a UITableView in edit mode, where the user is only allowed to reorder the rows, there is no permission to delete.

So, is there a way I can hide the red button from the TableView. Please let me know.

thank

+93
ios iphone uitableview cocoa
Jun 11 '10 at 7:25
source share
4 answers

Here is my complete solution, with no indent (left justify) cells!

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { return YES; } - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{ return UITableViewCellEditingStyleNone; } - (BOOL)tableView:(UITableView *)tableview shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath { return NO; } - (BOOL)tableView:(UITableView *)tableview canMoveRowAtIndexPath:(NSIndexPath *)indexPath { return YES; } 
+254
Oct 19 2018-10-19
source share

Swift 3 is equivalent to the accepted answer using only the necessary functions:

 func tableView(_ tableView: UITableView, shouldIndentWhileEditingRowAt indexPath: IndexPath) -> Bool { return false } func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCellEditingStyle { return .none } 
+36
Jan 22 '16 at 22:58
source share

This stops the indent:

 - (BOOL)tableView:(UITableView *)tableview shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath { return NO; } 
+4
Apr 10 2018-12-12T00:
source share

I had a similar problem when I wanted custom checkboxes to appear in edit mode but not the delete button (-).

Stefan's answer helped me in the right direction.

I created a toggle button and added it as editAccessoryView to the cell and linked it to the method.

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { .... // Configure the cell... UIButton *checkBoxButton = [[UIButton alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 40.0f, 32.0f)]; [checkBoxButton setTitle:@"O" forState:UIControlStateNormal]; [checkBoxButton setTitle:@"√" forState:UIControlStateSelected]; [checkBoxButton addTarget:self action:@selector(checkBoxButtonPressed:) forControlEvents:UIControlEventTouchUpInside]; cell.editingAccessoryType = UITableViewCellAccessoryCheckmark; cell.editingAccessoryView = checkBoxButton; return cell; } - (void)checkBoxButtonPressed:(UIButton *)sender { sender.selected = !sender.selected; } 

Implemented these delegate methods

 - (BOOL)tableView:(UITableView *)tableview shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath { return NO; } - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { return UITableViewCellEditingStyleNone; } 
+3
Feb 11 '15 at 11:33
source share



All Articles