UIWindow,UITabBarController,UINavigationController,UIViewController四者之間的關(guān)系

UIWindow

1.UIWindow是APP的窗口視圖,所有的展示內(nèi)容都是在window中的

2.常用方法

//設(shè)置tabbar為window的根控制器
self.window.rootViewController =  [[UITabBarController alloc]init];
//將單個界面設(shè)置為根控制器
self.window.rootViewController =  [[UINavigationController alloc]init];

UITabBarController

1.UITabBarController是控制App內(nèi)有幾個大模塊的控制中心(最多5個),單個模塊的圖標(biāo),標(biāo)題由該控制器控制(大部分情況下需要重寫)

2.常用Api

//創(chuàng)建tabbarController
UITabBarController *tabbarVC = [[UITabBarController alloc] init];
//設(shè)置單個模塊
UIViewController *vc = [[UIViewController alloc] init];
vc.title = @"首頁";
vc.tabBarItem.image = [UIImage imageNamed:@"home"];//設(shè)置為選中是的圖片
vc.tabBarItem.selectedImage = [UIImage imageNamed:@"home_sec"];//設(shè)置選中是的圖片

//創(chuàng)建導(dǎo)航欄控制器,并將第一個UIViewController設(shè)置為根控制器
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];

//將單個模塊添加到UITabBarController中
[tabbarVC addChildViewController:nav];

UINavigationController

1.UINavigationController是界面跳轉(zhuǎn)的控制中心,iOS界面跳轉(zhuǎn)有兩種方式,Push&&模態(tài)
2.常用Api

//創(chuàng)建UINavigationController
UIViewController *vc = [[UIViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];

//push跳轉(zhuǎn)
[nav pushViewController:vc animated:YES];
//pop返回
[nav popToRootViewControllerAnimated:YES];

//模態(tài)跳轉(zhuǎn)
[nav presentViewController:vc animated:YES completion:nil];
//模態(tài)返回
[vc dismissViewControllerAnimated:NO completion:nil];

UIViewController

  1. UIViewController具備控制界面的展示,處理界面里控件的點擊事件等功能
    2.常用Api
UIViewController *vc = [[UIViewController alloc] init];

四者之間的關(guān)系

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容