Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ios UITableView delete/re-arrange editing mode but not show delete icon

I have create a UITableView in editing mode, I force it run into editing mode on viewDidLoad function of a viewcontroller containing this tableview. Everything is fine, each row of table has a delete icon on the left, re-arrange icon on the right. I implemented

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

- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath 
{
     return YES;
}

The problem is on each row I don't want to show a red delete icon on the left, just show a re-arrange icon on the right. When user want to delete, he/she can swipe a row to delete.

The reason I want to do this is I don't encourage user to delete a row product. I understand I can put a Edit button, when user click on this button, I turn into Edit mode, but I don't want to do so, I want to display a re-arrange function on the beginning when user go into my viewcontroller.

Can I do so.

Let me put some screen shot

This is what I got

This is what I want to show. When user swipe I want to show a Delete button overlay the arrange icon on the right

The first image is what I got.

The second image is what I actually want to show. When user swipe I want to show a Delete button overlay the arrange icon on the right

like image 913
Scofield Tran Avatar asked May 30 '13 09:05

Scofield Tran


1 Answers

I don't think you can use swipe to delete when the tableview is in edit mode, instead you can add UISwipeGesture and implement your own custom button.

If you are doing with gestures then you need to implement following delegate methods of UITableView.

Setting the editing style to none:

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

This tells that the rows should not be indented while the table view is in editing mode

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

You can refer this link to know how to add swipe gesture to UITableView.

like image 53
Prasad Devadiga Avatar answered Nov 09 '22 23:11

Prasad Devadiga