iOS - didSelectRowAtIndexPath: is a UITableView delegate method which is called when the user selects a row on a table view. Navigation logic goes here.
– tableView:didDeselectRowAtIndexPath:
iOS Method within UITableView (Apple Docs)
Full method decleration:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
Overview
didSelectRowAtIIndexPath: is a method part of the uitableview delegate. The UITableView delegate handle setup and events for a UITableView.
This method is called when a user selects a row in the table view, and takes an argument of NSIndexPath. The NSIndexPath contains the row, and section of the cell which was selected. Within this method, actions are performed to react to a user's selection.
Unlike this method, willSelectRowAtIndexPath: is used to allow or disallow a selection based on the index path.
Similar methods include:
– tableView:willSelectRowAtIndexPath:
– tableView:willDeselectRowAtIndexPath:
- tableView:didDeselectRowAtIndexPath:
Sample Code
An implementation of this method designed to handle navigation logic might look like this:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *) {
NSUInteger row = [indexPath row]; // Easier to cache row, esp. in long methods
// In viewDidLoad you would have set up an array of controllers, then:
UIViewController *childController = [controllerArray objectAtIndex:row];
[self.navigationController pushViewController:childController];
}