天天看點

xcode11建立新項目時,黑屏了,不顯示View

在興沖沖更新了Xcode11,并建立了項目之後,且發現真機和模拟器都黑屏了,怎麼都不顯示View了。

然後項目中比之前莫名其妙的多出來了兩個檔案:

xcode11建立新項目時,黑屏了,不顯示View

APPdelegate.m中也多了兩段不明是以的代碼:

#pragma mark - UISceneSession lifecycle
- (UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession options:(UISceneConnectionOptions *)options {
    // Called when a new scene session is being created.
    // Use this method to select a configuration to create the new scene with.
    return [[UISceneConfiguration alloc] initWithName:@"Default Configuration" sessionRole:connectingSceneSession.role];
}
- (void)application:(UIApplication *)application didDiscardSceneSessions:(NSSet<UISceneSession *> *)sceneSessions {
    // Called when the user discards a scene session.
    // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
    // Use this method to release any resources that were specific to the discarded scenes, as they will not return.
}
           

經查詢資料得知,IOS13之後,生命周期時間就開始由

UISceneDelegate

接管了,一時間真的是措手不及啊,不過适應之前可以先通過以下辦法恢複到原來的項目結構:

  1. 删除info.plist中的

    Application Scene Manifest

    xcode11建立新項目時,黑屏了,不顯示View
  2. 删除項目中的Scenedelegate.h和Scenedelegate.m
  3. 删除掉APPdelegate.m中的

    #pragma mark - UISceneSession lifecycle

    代碼
  4. 在APPdelegate.h中添加

    @property (strong, nonatomic) UIWindow * window;

    屬性

然後,老朋友就還是熟悉的項目,熟悉的味道了。