不用系统的控制器,用自定义的方式创建控制器,所以要先删除ViewController.m、ViewController.m和main.storyboard。接着删除如下图所示的Main

在AppDelegate.m中添加以下代码
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
//1.创建window
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
//2.设置window的根控制
//>创建导航控制器
UINavigationController *nav = [[UINavigationController alloc] init];
self.window.rootViewController = nav;
UIViewController *vc = [[UIViewController alloc]init];
vc.view.backgroundColor = [UIColor yellowColor];
self.window.rootViewController = vc;
//3.将窗口z设置为主窗口并且可见
[self.window makeKeyAndVisible];
return YES;
}
本文介绍如何在iOS应用中不使用系统自带的ViewController及Storyboard,而是通过代码自定义启动流程。具体步骤包括删除默认文件、手动创建UIWindow、设置根ViewController,并使其可见。
1182

被折叠的 条评论
为什么被折叠?



