Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

didSelectRowAtIndexPath event not triggered when select row programmatically

I would like to select a cell in a tableView. It is working properly using this code, but once selected programmatically it does not trigger a didSelectRowAtIndexPath event. How can I trigger it?

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.mainTable selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
like image 413
Jaume Avatar asked Jan 02 '12 22:01

Jaume


1 Answers

It is working as documented:

Calling this method does not cause the delegate to receive a tableView:willSelectRowAtIndexPath: or tableView:didSelectRowAtIndexPath: message, nor will it send UITableViewSelectionDidChangeNotification notifications to observers.

Call it yourself after selecting your cell:

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];

[self tableView:self.mainTable willSelectRowAtIndexPath:indexPath];
[self.mainTable selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
[self tableView:self.mainTable didSelectRowAtIndexPath:indexPath];
like image 185
Guillaume Avatar answered Oct 22 '22 05:10

Guillaume