自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];
}
}