Reputation: 7778
I'm getting the warning above when selecting a segue in didSelectRowAtIndexPath. This is happening on an iPad. The iPhone gives a different warning, and I'll see if a fix to this also fixes the other.
I do have two segues in the method. The first works without incident. The second picks up the warning. I've looked around the net, and checked out others' solutions. nada, so I'm posting here..
Here's the code: (I'm open to better ways to write this!)
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//NSLog(@"%s", __FUNCTION__);
if ((indexPath.section == 0) || (indexPath.section == 1) || (indexPath.section == 2)) return;
if (indexPath.section > 4) return;
//Images THIS WORKS OK
if (indexPath.section == 3 && indexPath.row == 0) {
viewController1 = [[ViewController1 alloc] init];
[self performSegueWithIdentifier:@"detailToV1" sender:self];
[self.tableView reloadData];
}
if (indexPath.section == 3 && indexPath.row == 1) { // THIS REDULTS IN A WARNING
viewController2 = [[ViewController2 alloc] init];
[self performSegueWithIdentifier:@"detailToV2" sender:nil];
}
//Notes THIS WORKS OK BUT I HAD TO USE A NIB TO AVOID THE WARNING
if (indexPath.section == 4 && indexPath.row == 0) {
viewController3 = [[ViewController3 alloc] init];
[[self navigationController] pushViewController:viewController3 animated:YES];
[self.tableView reloadData];
}
}
Upvotes: 0
Views: 7246
Reputation: 1152
What is the parent class of ViewController3? It sounds like it is a navigation controller, and it is my understanding that you cannot push a navigation controller from within another navigation controller. If you want to do something like that you'd need to present the new navigation controller from the first navigation controller.
Edit:
Basically, if you use a navigation view controller to push another view controller, that new view controller remains "inside" the navigation view controller. (The navigation VC has logic to manage several VCs at once.) I believe there is a rule that no navigation VC can be "inside" another navigation VC. So you need to simply fall back on orindary VC presentation so that the new navigation VC is not "inside" the original navigation VC. Instead of being inside of it, it will essentially be on top of it.
Code example:
[self.navigationController presentViewController:ViewController3 animated:YES completion:nil]
Upvotes: 1