Question

I'm building an application based on the Utility template from Xcode, to which I have added some more views. My application structure would be as follows:

  • MainView (the app menu)

    • Flip-side view (a calculator)

    • UINavigationController

    • Settings view

      • viewDiDLoad: UITabBarController

                - Tab1 view (options)
                - Tab2 view (information text)
        

I can navigate correctly from my MainView to my Flip-side view, which is also the root view of the Navigation Controller. From my Flip-side view, I push a second view of my Navigation Controller (Settings view) that is configured to show an UITabBarController, with two tabs, as soon as it loads (with viewDidLoad).

If I remove the UITabBarController, I can return with no problems to my Flip-side view using "popViewController" from my Settings view. The problem comes if I load the UITabBarController in viewDiDLoad in my Settings view... the tabs work perfectly, but I'm not able to return to my Flip-side view (root view of the Navigation Controller) anymore.

I CAN return if I use the Navigation Bar of the Navigation Controller, but I want to configure my own buttons and have the Navigation Bar hidden.

So far I've tried the following methods:

  • [self.navigationController popViewControllerAnimated:YES];

  • [self.navigationController popToRootViewControllerAnimated:YES];

  • [self.navigationController popToViewController:FlipSideViewController animated:YES];

But they don't seem to work. The first two just do nothing (the screen remains as it was), and the third one does not recognize the "FlipsideViewController" (maybe because it's a delegate of the MainViewController?).

Is there a way to check what is exactly doing the "back" button of the Navigation Bar if I activate it?

Should I be using delegates?

Can I call a popViewController method in my Settings view from any of the two Tab views?

This is my Flip-side view:

- (IBAction)showSettingsView {
    SettingsViewController *controller = [[SettingsViewController alloc] initWithNibName:@"SettingsView" bundle:nil];
    controller.title = @"Settings";
    [self.navigationController pushViewController:controller animated:YES];
    [controller release];
}

This is my Settings view:

- (void)viewDidLoad {
    [super viewDidLoad];

    tabBarController = [[UITabBarController alloc] init];

    Tab1ViewController* vc1 = [[Tab1ViewController alloc] init];
    Tab2ViewController* vc2 = [[Tab2ViewController alloc] init];

    NSArray* controllers = [NSArray arrayWithObjects:vc1, vc2, nil];
    tabBarController.viewControllers = controllers;

    [self.view addSubview:tabBarController.view];
}

And the method to return in one of the Tab views:

- (IBAction)backFromTab1View {
    [self.navigationController popToViewController:FlipSideViewController animated:YES];
}

Thanks very much and sorry if the question is too basic!

Was it helpful?

Solution

I actually solved the problem creating my own UINavigationBar in the Settings view and using:

[self.view insertSubview:tabBarController.view belowSubview:myNavigationBar];

That inserts the rest of the view below the Navigation Bar and I still can use it to configure a button which pops the view and return to the previous screen.

It took me a while to realise the differences between "addSubview" and "inserSubview + belowSubview". Sorry about that!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top