XCODE 11-由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'-[AppDelegate窗口]:

问题描述 投票:0回答:2

最近我更新到XCODE 11,并了解了SceneDelegate和AppDelegate的概念。这是我在AppDelegate中的简单代码:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor yellowColor];
    return YES;
}

但是不幸的是,它在以下行中崩溃,如图所示:

enter image description here

它显示以下错误:

enter image description here

[请帮助我解决我面临的问题。任何帮助将不胜感激。

ios objective-c appdelegate xcode11 uiscenedelegate
2个回答
0
投票

假设您的根视图控制器的视图是透明的,这是在您的场景中设置UIWindow背景色的位置:

SceneDelegate.m中修改以下回调,如下所示:

- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
    if (scene.class == UIWindowScene.class) {
        [[(UIWindowScene *) scene windows].firstObject setBackgroundColor:UIColor.yellowColor];
    }
}

0
投票

删除屏幕代表:

转到info.plist并删除选定的条目,如下所示:enter image description here

从项目中删除ScreenDelegate.h和ScreenDelegate.m:enter image description here

将您的AppDelegate.h更新为:

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow * window;

@end

最后,从AppDelegates类中删除Screen委托:

enter image description here

希望有所帮助。

如果您想使用ScreenDelegates,您可以参考Asperi的答案

© www.soinside.com 2019 - 2024. All rights reserved.