gpt4 book ai didi

c# - 添加 UITabBarController 时出错

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:46:18 25 4
gpt4 key购买 nike

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

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

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

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

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

...

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

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

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

对标签栏 Controller 的调用最终将如下所示:

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

我猜这里还缺少一些额外的东西,但是在谷歌搜索和四处搜索之后,我找不到问题的答案。感谢您的帮助

最佳答案

如果您使用的是 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。

关于c# - 添加 UITabBarController 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17741506/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com