Serberuss
Serberuss

Reputation: 2387

Error when adding UITabBarController

I'm using Monotouch C# to write an iPhone App with a number of different screens. To keep things simple I will describe only a few screens that lead to the controller which I am having issues with.

The problem I am having is that I receive this error message when I create a class which inherits from UITabBarController:

Application windows are expected to have a root view controller at the end of application launch

In my AppDelegate class I initialise a UIViewController and a UINavigationController. I set my RootViewController on the UIWindow object to use the navigation controller like this:

var splashController = new SplashController(); // UIViewController
_navigationController = new UINavigationController(splashController);

...

_window = new UIWindow(UIScreen.MainScreen.Bounds);
_window.RootViewController = _navigationController;
_window.MakeKeyAndVisible();

Up until now I haven't had an issue with running my applications. However I created a new class which inherits from UITabBarController and I get an error message described above. I can post the code to it if needs be but I've also tried running my application with an empty class which inherits from UITabBarController and I still receive the same error message.

Even if the class never gets called in my code through commenting out or deleting the PushViewController call I still can't run the application.

The call to the tab bar controller will eventually look like this:

SplashController (UIViewController) > push > HomeController (UIViewController) > push > MenuController (DialogViewController) > push > StatsController (UITabBarController)

I'm guessing there's something extra that I am missing here but after Googling and searching around I couldn't find an answer to my problem. Thanks for any help

Upvotes: 2

Views: 233

Answers (2)

Vish
Vish

Reputation: 341

I guess this link may help you

Applications are expected to have a root view controller at the end of application launch

Also some times it occurs when we don't mention initial view controller in plist.

Upvotes: 1

Florian Schaal
Florian Schaal

Reputation: 2660

If you are using a UITabBarController it should look something like this:

window = new UIWindow (UIScreen.MainScreen.Bounds);

            var viewController1 = new FirstViewController ();
            var viewController2 = new SecondViewController ();

            tabBarController = new UITabBarController ();
            tabBarController.ViewControllers = new UIViewController [] {
                viewController1,
                viewController2,
            };

            window.RootViewController = tabBarController;
            window.MakeKeyAndVisible ();

The UITabBarController should be the RootViewController.

Upvotes: 3

Related Questions