1. 在AppDelegate.m文件中找到application:didFinishLaunchingWithOptions:方法。
  2. 创建一个新的UIWindow对象:UIWindow *newWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  3. 创建一个新的ViewController对象:UIViewController *newController = [[UIViewController alloc] init];
  4. 将该ViewController设置为newWindow的根视图控制器:newWindow.rootViewController = newController;
  5. 显示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;
}
IOS OC 在新建的window中添加一个controller

原文地址: https://www.cveoy.top/t/topic/bkhd 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录