添加UITabBarController时出错

时间:2013-07-19 08:32:19

标签: c# iphone ios xamarin.ios uitabbarcontroller

我正在使用 Monotouch C#来编写具有多个不同屏幕的iPhone应用程序。为了简单起见,我将仅描述一些导致我遇到问题的控制器的屏幕。

我遇到的问题是,当我创建一个继承自 UITabBarController 的类时,我收到此错误消息:

  

应用程序窗口应该有一个根视图控制器   应用程序启动结束

在我的AppDelegate类中,我初始化了一个UIViewController和一个UINavigationController。我在UIWindow对象上设置我的RootViewController以使用这样的导航控制器:

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

...

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

到目前为止,我还没有遇到运行应用程序的问题。但是我创建了一个继承自UITabBarController的新类,我收到了上面描述的错误消息。如果需要,我可以将代码发布到它,但我也尝试使用从UITabBarController继承的空类运行我的应用程序,但仍然收到相同的错误消息。

即使通过注释掉或删除PushViewController调用从未在我的代码中调用类,我仍然无法运行该应用程序。

对标签栏控制器的调用最终将如下所示:

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

我猜这里有一些额外的东西我在这里失踪但是在谷歌搜索并搜索后我无法找到问题的答案。谢谢你的帮助

2 个答案:

答案 0 :(得分:3)

如果您使用的是UITabBarController,它应该如下所示:

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 ();

UITabBarController应该是RootViewController。

答案 1 :(得分:1)

我猜这个链接可以帮到你

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

有时我们在plist中没有提到初始视图控制器时会发生这种情况。

相关问题