更新Xcode11之后,洗掉Main.storyboard,且洗掉Main storyboard file base name之后運行報錯
Xcode11自動新增了一個SceneDelegate檔案,查找了一下官方檔案WWDC2019:Optimizing App Launch 發現iOS13中appdelegate的職責發現了改變:
iOS13之前,Appdelegate的職責全權處理App生命周期和UI生命周期;
iOS13之后,Appdelegate的職責是:
1、處理 App 生命周期
2、新的 Scene Session 生命周期
那UI的生命周期呢?交給新增的Scene Delegate處理, Appdelegate不在負責UI生命周期,所有UI生命周期交給SceneDelegate處理
因此Xcode11之后,除了與以前一樣,要在專案Info.plist洗掉Main storyboard file base name之外, 還要洗掉SceneDelegate的StoryboardName

或者在General----Deployment Info----Main Interface中清除Main.storyboard

在AppDelegate中自定義UIWindow,代碼不起作用
因此初始化window方法需要改變: 現在不再在Appdelegate的- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions進行初始化
而是在SceneDelegate中初始化了
- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
UIWindowScene *windowScene = (UIWindowScene *)scene;
self.window = [[UIWindow alloc] initWithWindowScene:windowScene];
MainViewController *launchVC = [[MainViewController alloc] init];
self.window.rootViewController = launchVC;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/282651.html
標籤:其他
