I am implementing an a UITableView and have the - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath method implemented and within that method I have if loops (below):
NSInteger row = [indexPath row];
if (self.someDetailViewController == nil) {
if (row==0) {
OneTableViewController *aDetail = [[OneTableViewController alloc] initWithNibName:@"OneDetail" bundle:nil];
self.oneDetailViewController = aDetail;
[aDetail release];
} else if (row==1) {
OneTableViewController *aDetail = [[OneTableViewController alloc] initWithNibName:@"TwoDetail" bundle:nil];
self.oneDetailViewController = aDetail;
[aDetail release];
}
}
However each time I select something in my table view (let’s say row 0) I am taken to the secondary view (OneDetail) and then when I go back and select another row (row 1) and I expect to go to the other view (TwoDetail) however I am taken to OneDetail (to original row that was selected first) – how can this be when the user taps another row they are taken to the first row’s secondary view that was originally tapped. This also happens vice versa (i.e. selecting row 1 and being taken to TwoDetail and then going back and selecting row 0 and also being taken to TwoDetail not OneDetail…
I was wondering if anyone knew how to ‘restart’ an if loop when the user presses the back button or how to overcome my issue in some other fashion. Thanks so much in advance!
I suspect that the second time you enter the method, this check is returning false:
if (self.someDetailViewController == nil)Thus, you never get into the part where you check which row you’re on, and you’re permanently stuck with whichever one you set first.