简体   繁体   中英

Pop to another view controller in navigation controller hierarchy

I have tree view controllers embed in navigation controller. The first one contains conversations, the second contains messages of a particular conversation. The third is to create new conversation.

The view controllers structure

When a user creates new conversation he's redirecting to second controller with conversations. So the question is when a users has been redirected from the third controller to second vc and taps Back button on the second view controller how to pop out from the second view controller to first after creating new conversation. Because the navigation controller pops user to previous controller - third controller new conversations.

PS The first view controller isn't root controller. There are several controllers before.

I asked it some time ago and now I became smarter so I can answer my own question in a really right way.

I had to use modal view controller. Thus when we want to create a new conversation we're showing the third VC as a modal view controller, and when the conversation is created we're delegating about this to the first VC . In the first view controller I'm creating the second VC and pushing it after that I dismissed the modal VC.

NewConversationViewController *vc = [NewConversationViewController new]; //any setups
[self.navigationController pushViewController:vc animated:NO];
[self dismissViewControllerAnimated:modalVC completion:nil];

You need to do something like. By adding custom back button on navigationBarItem.

    NSArray *viewContrlls=[[self navigationController] viewControllers];
    for( int i=0;i<[ viewContrlls count];i++){
        id obj=[viewContrlls objectAtIndex:i];
        if([obj isKindOfClass:[ManageAlertsListViewController class]] ){
            [[self navigationController] popToViewController:obj animated:YES];
            return;
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM