Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically "tap" a UITableView cell?

Tags:

I was wondering is there a way that I could have my code "tap" a cell in my UITableView in order to reproduce the behaviour specified in the - (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath delegate method.

I guess in other words, is is possible to invoke the - (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath delegate method programatically?

like image 236
Christian Gossain Avatar asked May 07 '11 00:05

Christian Gossain


1 Answers

if you want to have the cell selected, i.e highlight a specific cell:

//select first row of first section NSIndexPath* selectedCellIndexPath= [NSIndexPath indexPathForRow:0 inSection:0]; [self.tableView selectRowAtIndexPath:selectedCellIndexPath animated:false scrollPosition:UITableViewScrollPositionMiddle]; 

if you want to additionally trigger actions in your didSelectRowAtIndexPath method, you need to manually call the delegate method, it won't happen automatically:

[self tableView:self.tableView didSelectRowAtIndexPath:selectedCellIndexPath]; 
like image 85
Benoit Schmitlin Avatar answered Sep 22 '22 11:09

Benoit Schmitlin