Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS: Get row position in a sectioned TableView

Is it able to acces selected row position in a sectioned table view within a prepareForSegue method?

This is my code for Segue:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{

if ([[segue identifier] isEqualToString:@"CurrentEvent"]) {

    Tab1_DetailTableViewController *vc = [segue destinationViewController];

    // get the selected index
    NSInteger selectedIndex = [[self.tableView indexPathForSelectedRow] row];

}
}

I looked up several methods to acces the position directly, but i didn't find one. I think I have overseen something. Does anybody know a way?

like image 615
Bins Ich Avatar asked Dec 30 '11 22:12

Bins Ich


1 Answers

To get the selected indexpath:

NSIndexPath *selectedRowIndexPath = [self.tableview indexPathForSelectedRow];

To get the selected row

NSUInteger selectedRow = selectedIndexPath.row;

To get the selected section

NSUInteger selectedSection = selectedIndexPath.section;

To get the selected cell:

UITableViewCell *selectedCell = [self.tableview cellForRowAtIndexPath:selectedRowIndexPath];
like image 120
Rog Avatar answered Nov 14 '22 15:11

Rog