Xcode11 之前:
window 在 AppDelegate 中设置:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
self.window.rootViewController = [SSHomeVC new];
[self.window makeKeyAndVisible];
return YES;
}
使用 Xcode11 创建的项目中:
除了自动创建AppDelegate 文件外,还创建了SceneDelegate文件,这适用于 iOS13 之后.此时 AppDelegate 文件中已经没有 UIWindow 对象,而在 SceneDelegate中:
#import <UIKit/UIKit.h>
@interface SceneDelegate : UIResponder <UIWindowSceneDelegate>
@property (strong, nonatomic) UIWindow * window;
@end
此时自定义UIWindow,设置控制器需要:
- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
UIWindowScene *windowScene = (UIWindowScene *)scene;
self.window = [[UIWindow alloc] initWithWindowScene:windowScene];
self.window.rootViewController = [SSHomeVC new];
[self.window makeKeyAndVisible];
}