Nic Hubbard
Nic Hubbard

Reputation: 42139

UITableView in editing mode cell still selectable even when using

I have a UITableView that has AllowsMultipleSelectionDuringEditing set to YES. Selecting multiple rows is a big part of my app, and it works great.

The problem is, that on one of my tableView's I don't want the user to be able to select the first 2 rows when in editing mode, so I have implemented the following:

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {

    if (indexPath.row == 0 || indexPath.row ==1) {
        return NO;
    }//end

    return YES;

}//end

This works how I thought it would, and doesn't show the red checkbox graphic or the option to re-sort the rows. BUT, I can still select those rows that are not editable, and call the indexPathsForSelectedRows method and return the indexPaths of those rows.

How can I prevent the user COMPLETELY from being able to select those rows while in editing mode, and prevent touches on those from being returned when calling indexPathsForSelectedRows? Why isn't canEditRowAtIndexPath: doing this for me?

Upvotes: 1

Views: 1546

Answers (2)

Paramasivan Samuttiram
Paramasivan Samuttiram

Reputation: 3738

Did you try the following code?

tableView.allowsSelectionDuringEditing = NO;

or

tableView.allowsMultipleSelectionDuringEditing = NO;

Upvotes: 1

iDev
iDev

Reputation: 23278

One way to do this would be to implement – tableView:willSelectRowAtIndexPath: method and check if tableView.editing == YES then return nil for first two cells.

Something like,

- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    if (tableView.editing == YES && indexPath.row < 2 ) 
       return nil;

    return indexPath;
}

You can also set the selectionStyle of these two cells as UITableViewCellSelectionStyleNone in editing mode in cellForRowAtIndexPath method.

Upvotes: 1

Related Questions