【问题标题】:xamarin error : NSInternalInconsistencyException Reason: Application windows are expected to have a root view controller at the end of applicationxamarin 错误:NSInternalInconsistencyException 原因:应用程序窗口应在应用程序结束时具有根视图控制器
【发布时间】:2021-04-14 11:07:23
【问题描述】:

我正在尝试重新组织用 Xamarin 编写的旧应用程序。该应用程序在未在模拟器中打开应用程序的情况下给出以下错误。你能帮帮我吗?

抛出了 Objective-C 异常。名称:NSInternalInconsistencyException 原因:应用程序窗口在应用程序启动结束时应该有一个根视图控制器 本机堆栈跟踪: 0 核心基础 0x00007fff20421af6 __exceptionPreprocess + 242 1 libobjc.A.dylib 0x00007fff20177e78 objc_exception_throw + 48 2 核心基础 0x00007fff2042191f +[NSException raise:format:] + 0 3 基础 0x00007fff2077156a -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 191 4 UIKitCore 0x00007fff2469a8fc-[UIApplication_runWithMainScene:transitionContext:completion:] + 2148 5 UIKitCore 0x00007fff23cc36f7 -[_UISceneLifecycleMultiplexer completeApplicationLaunchWithFBSScene:transitionContext:] + 122 6 UIKitCore 0x00007fff24251d1e _UIScenePerformActionsWithLifecycleActionMask + 88 7 UIKitCore 0x00007fff23cc4206 __101-[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransitionStore:]_block_invoke + 198 8 UIKitCore 0x00007fff23cc3cca -[_UISceneLifecycleMultiplexer _performBlock:withApplicationOfDeactivationReasons:fromReasons:] + 474 …… enter image description here

【问题讨论】:

  • 您是在 xamarin.forms 还是 xamarin.ios 中开发应用程序?
  • 请不要创建代码图像。它违反了 SO 准则。您可以使用 markdown 轻松地在 SO 中编写代码。
  • xamarin.ios 开发

标签: xamarin xamarin.forms xamarin.ios


【解决方案1】:

iOS9 要求所有的 Window 必须有一个 rootViewController,你应该像这样编辑 AppDelegate:

public override bool FinishedLaunching (UIApplication application, NSDictionary launchOptions)
        {
            // Override point for customization after application launch.
            // If not required for your application you can safely delete this method

            var indexVC = new IndexViewController ();
            window = new UIWindow ((CGRect)UIScreen.MainScreen.Bounds);
            window.RootViewController = indexVC;
            window.MakeKeyAndVisible ();


            return true;
        }

您可以参考this page了解更多详情。

从ios9开始有一些变化,可以参考thisthis页面

【讨论】:

  • 嗨史蒂文,感谢您的回复。我仍然有问题,我无法解决它。
  • var indexVC = new customViewController(); window = new UIWindow((CGRect)UIScreen.MainScreen.Bounds); window.RootViewController = indexVC; window.MakeKeyAndVisible();公共部分类 customViewController: UIViewController { public customViewController(IntPtr handle) : base(handle) { } public customViewController(NSCoder coder) : base(coder) { } public customViewController() : base("customViewController", null) { } 公共覆盖bool ShouldAutorotateToInterfaceOrientation UIInterfaceOrientation toInterfaceOrientation) { return true; } }
猜你喜欢
  • 2016-09-24
  • 2017-06-12
  • 1970-01-01
  • 1970-01-01
  • 2012-04-08
  • 1970-01-01
  • 1970-01-01
  • 2015-12-16
  • 2012-02-01
相关资源
最近更新 更多