How do I programmatically select a UITableView
row so that
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath
gets executed? selectRowAtIndexPath
will only highlight the row.
How do I programmatically select a UITableView
row so that
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath
gets executed? selectRowAtIndexPath
will only highlight the row.
if you want to select some row this will help you
This will also Highlighted the row. Then delegate
Swift 3.0 Solution
Select Row
DeSelect Row
There are two different methods for iPad and iPhone platforms, so you need to implement both:
segue.
Like Jaanus told:
So you just have to call the
delegate
method yourself.For example:
Swift 3 version:
ObjectiveC version:
Swift 2.3 version:
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.From reference documentation:
What I would do is:
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.