How do I programmatically select a tableview row so that
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
gets executed? selectRowAtIndexPath will only highlight the row.
How do I programmatically select a tableview row so that
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
gets executed? selectRowAtIndexPath will only highlight the row.
UITableView's selectRowAtIndexPath:animated:scrollPosition: should do the trick.
Just pass UITableViewScrollPositionNone
for scrollPosition and the user won't see any movement.
You should also be able to manually run the action:
[theTableView.delegate tableView:theTableView didSelectRowAtIndexPath:indexPath]
after you selectRowAtIndexPath:animated:scrollPosition: so the highlight happens as well as any associated logic.
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.
What I would do is:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self doSomethingWithRowAtIndexPath:indexPath];
}
And then, from where you wanted to call selectRowAtIndexPath, you instead call doSomethingWithRowAtIndexPath. On top of that, you can additionally also call selectRowAtIndexPath if you want the UI feedback to happen.