Xcode11 中iOS项目自定义控制器

Xcode11 中iOS项目自定义控制器

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    self.window.rootViewController = [WWHomeVC new];
    [self.window makeKeyAndVisible];
    return YES;
}
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchWithOptions launchOptions: [NSObject: AnyObject]?) -> bool {
	window = UIWIndow(frame: UIScreen.mainScreen().bounds)
	window?.backgroundColor = UIColor.whiteColor()
	window?.rootViewController = MainViewController()
	window?makeKeyAndVisible()
	return true
}

使用 Xcode11 创建的项目中:
除了自动创建AppDelegate 文件外,还创建了SceneDelegate文件,这适用于 iOS13 之后.
此时 AppDelegate 文件中已经没有 UIWindow 对象,而在 SceneDelegate中:
此时自定义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];
}
hmoban主题是根据ripro二开的主题,极致后台体验,无插件,集成会员系统
自学咖网 » Xcode11 中iOS项目自定义控制器