Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Monotouch UITabBarController + UINavigationController

I'm getting a little lost trying to use both a UITabBarController and UINavigationController in MonoTouch.

I can create a navigation based project, and navigate using only a navigationController, fine. Or I can add a tabBarController and navigating to a couple of main screens, fine.

However, I can't seem to navigate to another without using the TabBarController if one is present. E.g, I'm doing an app that deals with "foo", so I am two views on my tabbar, FooHome, and FooSettings. How do I navigate to a new view if the user click something like "Add Foo" on the FooSettings view.

The NavigationController.PushToView doesn't seem to have any effect, and I don't want to add the view to the tabController since its nice and simple with only two items.

Should I be using this.View.AddSubView? The idea sort of sounds like a dialog box, I'm just not sure how to do it with monoTouch...

like image 474
Kye Avatar asked Jul 01 '11 14:07

Kye


2 Answers

I was wrestling with this for hours and this post helped. Thank you so much. For those still in the dark a little, here's my code:

    public override bool FinishedLaunching (UIApplication app, NSDictionary options)
    {
        // create a new window instance based on the screen size
        window = new UIWindow (UIScreen.MainScreen.Bounds);

        var vc1 = new VideosVC ();
        var vc2 = new ScheduleVC ();
        var vc3 = new TheCastVC ();
        var vc4 = new MerchandiseVC ();

        UINavigationController uinc1 = new UINavigationController(vc1);
        UINavigationController uinc2 = new UINavigationController(vc2);
        UINavigationController uinc3 = new UINavigationController(vc3);
        UINavigationController uinc4 = new UINavigationController(vc4);

        tabBarController = new UITabBarController ();

        tabBarController.ViewControllers = new UIViewController [] {
            uinc1,
            uinc2,
            uinc3,
            uinc4,
        };

        window.RootViewController = tabBarController;

        window.MakeKeyAndVisible ();

        return true;
    }
like image 141
Brian Pautsch Avatar answered Sep 30 '22 14:09

Brian Pautsch


Add your FooHome and FooSettings controllers to UINavigationControllers and set those navigation controllers to your tab controller.

So for example, the first tab will contain a navigation controller whose root controller is FooHome and the second tab will contain a navigation controller whose root controller is FooSettings.

When you tap on Add Foo in FooSettings, you will push the new controller inside the second tab.

like image 35
Dimitris Tavlikos Avatar answered Sep 30 '22 12:09

Dimitris Tavlikos