自xcode11新增SceneDelegate后,SceneDelegate與Man.storyboard該如何處理:
1. 第一種情況,刪除SceneDelegate,但保留Man.storyboard:
- 刪除info.plist中的
Application Scene Manifest
一項 - 在AppDelegate.h中添加window屬性
@property (strong, nonatomic) UIWindow *window;
- 刪除AppDelegate.m中新增的兩個UIScene方法
- 刪除UISceneDelegate類文件
切記要在AppDelegate.h中添加window屬性,否則Man.storyboard無法正常加載
2. 第二種情況,刪除SceneDelegate且刪除Man.storyboard:
- 刪除info.plist中的
Application Scene Manifest
一項 - 在AppDelegate.h中添加window屬性
@property (strong, nonatomic) UIWindow *window;
- 刪除AppDelegate.m中新增的兩個UIScene方法
- 刪除UISceneDelegate類文件
- 刪除Main.storeboaard文件
- 項目
TARGETS->General->Main Interface
置為空 - 刪除info.plist中
Main storyboard file base name
一項 - AppDelegate.m中導入目標頭文件,在
didFinishLaunchingWithOptions
方法中添加目標類:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc] init];
self.window.frame = [UIScreen mainScreen].bounds;
self.window.backgroundColor = [UIColor whiteColor];
ViewController * vc = [[ViewController alloc]init];
self.window.rootViewController = vc;
[self.window makeKeyAndVisible];
return YES;
}
3. 第三種情況,保留SceneDelegate但刪除Man.storyboard:
- 項目
TARGETS->General->Main Interface
置為空 - 刪除info.plist中
Main storyboard file base name
一項 - 刪除info.plist中
Application Scene Manifest -> Scene Configuration -> Application Scene Role -> Item 0 -> Storyboard name
一項 - SceneDelegate.m中導入目標頭文件,在
willConnectToSession
方法中添加目標類:
- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
if ([scene isKindOfClass:[UIWindowScene class]]) {
UIWindowScene *windowScene = (UIWindowScene*)scene;
self.window = [[UIWindow alloc] initWithWindowScene:windowScene];
self.window.frame = [UIScreen mainScreen].bounds;
self.window.backgroundColor = [UIColor whiteColor];
ViewController * vc = [[ViewController alloc]init];
self.window.rootViewController = vc;
[self.window makeKeyAndVisible];
}
}