I want to access the UITableViewCell that is after the one that is selected and select that one,
int b = lastIndexPath.row + 1; //lastIndexPath references to the current selected cell index path
NSIndexPath *myNextIndex = [[NSIndexPath alloc]initWithIndex:b];
[self tableView:table didSelectRowAtIndexPath:myNextIndex];
so up to this point everything works fine, the b value is 2. but when the tableView:didSelectRowAtIndexPath: and I want to get the value of i,
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
int i = indexPath.row;
//some other stuff
}
I get the value 81809923 for i, but the value of i should be 2.
I don’t know why this would happen. if anyone has any idea please help.
thanks
Positions in a
UITablleVieware keyed by both section and row (even if your table only has a single section). The iOS SDK adds a utility method specifically for the purpose of making it easier to work with table views.In this case, you would use it like:
As for your
81809923value, that is probably random garbage that happened to be in memory, since your original code does not assign any value to therowfield of theNSIndexPath.