Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select rows while in edit mode?

I have a UITableView that is editable. I am commiting changes via:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath

While in edit mode, I would like the user to be able to select a row, which will push a new view. I am not sure how to do this. I suspect it will be in:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

But how can I determine if the user is in edit mode or not?

UPDATE: Edit Mode is toggled via:

self.navigationItem.rightBarButtonItem = self.editButtonItem;
like image 804
Sheehan Alam Avatar asked Jul 19 '10 03:07

Sheehan Alam


1 Answers

To allow selection during editing you need to set the allowsSelectionDuringEditing property of UITableView to YES. Then it will call the didSelectRowAtIndexPath message. You can find more information about that property here:

http://developer.apple.com/iphone/library/documentation/uikit/reference/UITableView_Class/Reference/Reference.html#//apple_ref/occ/instp/UITableView/allowsSelectionDuringEditing

Then, you can see if the user is in edit mode by running code like the following:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (tableView.editing == YES) {
        // Table view is editing - run code here
    }
}
like image 63
rickharrison Avatar answered Oct 26 '22 17:10

rickharrison