When editing, `UITableView` does not call didSelectRowAtIndexPath ??

IphoneUitableview

Iphone Problem Overview


I have a UITableViewController where the user should be able to edit the items. In order to enable editing I use this :

self.navigationItem.rightBarButtonItem = self.editButtonItem;

For everyone who does not know where self.editButtonItem comes from, it is predefined by the SDK.

So, now when I press on any item, this method is called :

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

but as soon as I hit the edit button and while editing is active, this method does not seemed to be called.

Any idea what I missing ?

This is the rest of the code that is related to editing :

// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath 
{
	// Return NO if you do not want the specified item to be editable.
	return YES;
}

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


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

Thanks for the help.

mcb

Iphone Solutions


Solution 1 - Iphone

You gotta set the allowsSelectionDuringEditing property of UITableView to true.

Reference: UITableView - allowsSelectionDuringEditing

Solution 2 - Iphone

Do you set the self.editing = YES when the edit button is tapped?

When in editing mode this method is called, instead of didSelectRow when you tap a row:

tableView:commitEditingStyle:forRowAtIndexPath:.

Solution 3 - Iphone

I solved this problem other way. My Edit button was on my own Navigation bar and that was the reason it wasn't called. After I've embedded VC inside Navigation Controller, and put new Edit button inside its Navigation Item, Edit button started to get called.

Solution 4 - Iphone

Short answer (Swift lang):

@IBOutlet private weak var tableView: UITableView!

override func viewDidLoad() {
    super.viewDidLoad()

    tableView.allowsSelectionDuringEditing = true // Magic happens here
}

Solution 5 - Iphone

> but as soon as I hit the edit button and while editing is active, this method does not seemed to be called. > > Any idea what I missing ?

Yes. You are expecting tableView:didSelectRowAtIndexPath: to be called when a button in your nav bar is tapped. This will never happen. That method is only called when a row is selected.

When the edit button is tapped, you will want to put your table into editing mode. In your view controller:

- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
    [super setEditing:editing animated:animated]; // must be called first according to Apple docs

    [self.tableView setEditing:editing animated:animated];
}

Then you handle editing events by adding a tableView:commitEditingStyle:forRowAtIndexPath: method.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionelementsenseView Question on Stackoverflow
Solution 1 - IphoneDanielView Answer on Stackoverflow
Solution 2 - IphoneRickiGView Answer on Stackoverflow
Solution 3 - IphoneRealNmaeView Answer on Stackoverflow
Solution 4 - IphonenurtuganView Answer on Stackoverflow
Solution 5 - IphoneShaggy FrogView Answer on Stackoverflow