AppDelegate.m手动添加NavigationController和TabBarController

纯代码编写APP时在AppDelegate.m里面添加NavigationController和TabBarController的代码如下图:

AppDelegate.m手动添加NavigationController和TabBarController_第1张图片

详细代码如下:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

UIWindow *window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];

_window = window;

_window.backgroundColor = [UIColor whiteColor];

_window.hidden = 0;

QYNewsViewController *firstVC = [[QYNewsViewController alloc] init];

UINavigationController *firstNav = [[UINavigationController alloc] initWithRootViewController:firstVC];

QYReaderViewController *secondVC = [[QYReaderViewController alloc] init];

UINavigationController *secondNav = [[UINavigationController alloc] initWithRootViewController:secondVC];

QYVideoViewController *thirdVC = [[QYVideoViewController alloc] init];

UINavigationController *thirdNav = [[UINavigationController alloc] initWithRootViewController:thirdVC];

QYDiscoverViewController *forthVC = [[QYDiscoverViewController alloc] init];

UINavigationController *forthNav = [[UINavigationController alloc] initWithRootViewController:forthVC];

QYMeViewController *fifthVC = [[QYMeViewController alloc] init];

UINavigationController *fifthNav = [[UINavigationController alloc] initWithRootViewController:fifthVC];

NSArray *viewControllers = @[firstNav,secondNav,thirdNav,forthNav,fifthNav];

UITabBarController *mainViewController = [[UITabBarController alloc] init];

mainViewController.viewControllers = viewControllers;

mainViewController.tabBar.tintColor = [UIColor colorWithRed:94/255.0 green:211/255.0 blue:44/255.0 alpha:1.0];

_window.rootViewController = mainViewController;

return YES;

}

你可能感兴趣的:(AppDelegate.m手动添加NavigationController和TabBarController)