Search code examples
iosobjective-cuitableviewios7uistoryboardsegue

Segue not passing correct indexpath of row always section 0


I'm used sectioned tableView.If I click tableview always it passing indexpath 0 to detail view controller.If I click second row but it indexpath pass always pass 0.

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    if ([segue.identifier isEqualToString:@"toNext"]) {
    detailTableViewController *detailVC = [segue destinationViewController];
    [detailVC setkMessageDict:(NSDictionary*)[nArray objectAtIndex:[self.mytableView indexPathForSelectedRow].section]];
}

What's wrong in code?


Solution

  • - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
        if ([segue.identifier isEqualToString:@"toNext"]) {
        NSIndexPath *selectedIndex= [self.mytableView indexPathForSelectedRow];
        NSDictionary *myDic=(NSDictionary*)[nArray objectAtIndex:indexpath.section];
        detailTableViewController *detailVC = [segue destinationViewController];
        [detailVC setkMessageDict:(NSDictionary*)[[myDic objectForKey:@"locations"] objectAtIndex:selectedIndex.row]];
    }
    

    Please check your Array having the proper data from your section tableview otherwise add the NSDictionary value to array and pass it to detailTableViewController then try.Problem is your are not passing indexpath of section here.Hope its helpful for you.