0

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.

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

DenFav
  • 2,683
  • 1
  • 18
  • 27
  • If you want Back to pop two view controllers rather than one, then you shouldn't be Pushing the New Conversation VC in the first place, it's more like it's replacing the conversations VC than pushing on top of it. – Airsource Ltd Mar 06 '15 at 13:07
  • possible duplicate of [Setting action for back button in navigation controller](http://stackoverflow.com/questions/1214965/setting-action-for-back-button-in-navigation-controller) – Avt Mar 06 '15 at 13:11
  • Seems that you need a custom action for back button. Try following http://stackoverflow.com/questions/1214965/setting-action-for-back-button-in-navigation-controller – Avt Mar 06 '15 at 13:12
  • I know how to create custom action for a back button. The problem is when I wrote the code that creates new view controller that is exists already in memory. And I want to return to existing view controller in navigation controller. – DenFav Mar 08 '15 at 14:21

2 Answers2

2

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];
ZygD
  • 22,092
  • 39
  • 79
  • 102
DenFav
  • 2,683
  • 1
  • 18
  • 27
0

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;
        }
    }
Zahid
  • 552
  • 3
  • 11
  • But am I creating a new view controller in this way? Or I'm returning to previous that was saved in memory? – DenFav Mar 08 '15 at 14:16
  • In this you only jump to previous viewController in stack of navigationController – Zahid Mar 08 '15 at 14:19
  • Great. Thank you. That's it. But when I jump to previous using this code there's no navigation bar. How to six it? – DenFav Mar 08 '15 at 18:21
  • There might be something else which is disturbing your navigation. Cannot suggest any solution without having look at code. – Zahid Mar 08 '15 at 19:00