IOS OC 在新建的window中添加一个controller
- 在AppDelegate.m文件中找到
application:didFinishLaunchingWithOptions:方法。 - 创建一个新的UIWindow对象:
UIWindow *newWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; - 创建一个新的ViewController对象:
UIViewController *newController = [[UIViewController alloc] init]; - 将该ViewController设置为newWindow的根视图控制器:
newWindow.rootViewController = newController; - 显示newWindow:
[newWindow makeKeyAndVisible];
完整代码示例:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// 创建新的window
UIWindow *newWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
// 创建新的ViewController
UIViewController *newController = [[UIViewController alloc] init];
// 将ViewController设置为newWindow的根视图控制器
newWindow.rootViewController = newController;
// 显示newWindow
[newWindow makeKeyAndVisible];
return YES;
}
原文地址: https://www.cveoy.top/t/topic/bkhd 著作权归作者所有。请勿转载和采集!