UINavigationController和UITabBarController

使用一个控制器A去管理多个控制器,如B,C;控制器A称为父控制器,B,C称为子控制器;

iOS提供了这两个比较特殊的控制器,根据需要可以自定义;

UINavigationController:

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

{

// Override point for customization after application launch.

// 创建窗口

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

// 窗口背景色

_window.backgroundColor = [UIColor whiteColor];

// 实例控制器 a

AViewController *a = [[AViewController alloc] init];

// 实例导航控制器 nav

UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:a];

// 设置根控制器为nav

self.window.rootViewController = nav;

//

[_window makeKeyAndVisible];

return YES;

}

UITabBarController:

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

{

// Override point for customization after application launch.

// 创建窗口

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

// 窗口背景色

_window.backgroundColor = [UIColor whiteColor];

// 实例控制器 a

AViewController *a = [[AViewController alloc] init];

BViewController *b = [[BViewController alloc] init];

// 实例导航控制器 anav

UINavigationController *anav = [[UINavigationController alloc] initWithRootViewController:a];

UINavigationController *bnav = [[UINavigationController alloc] initWithRootViewController:b];

// 实例tab

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

// nav加到tab上

tab.viewControllers = @[anav, bnav];

// 设置根控制器为nav

self.window.rootViewController = tab;

//

[_window makeKeyAndVisible];

return YES;

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容