iOS, How to find selected row Of UITableView?
Objective C
NSIndexPath *selectedIndexPath = [tableView indexPathForSelectedRow];
Swift code
let indexPathForSelectedRow = self.tableView.indexPathForSelectedRow
Use this delegate method of UITableView
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ NSLog(@"%d", indexPath.row); // you can see selected row number in your console;}
in UITableViewDataSource delegate there is a method - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath.
It returns NSIndexPath object which caontains both the selected section and selected row.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ NSLog(@"Selected section>> %d",indexPath.section); NSLog(@"Selected row of section >> %d",indexPath.row);}
make sure to set datasource of tableview before using it otherwise this method won't be called