ios7 - Warning: Attempt to present UINavigationController on UINavigationController while a presentation is in progress

梦想的初衷 提交于 2019-12-11 19:35:36

问题


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];

    }
}

回答1:


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]


来源:https://stackoverflow.com/questions/21386613/ios7-warning-attempt-to-present-uinavigationcontroller-on-uinavigationcontrol

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!