項目開始時 最初的框架搭建舅踪,代碼寫了一個簡單的 包含 (UINavgationController,UITabBarController,UIViewController)的三級控制器界面 ,幫助新手更好的入門 開始程序的編寫 , 如有不妥之處 匾荆,歡迎提出意見 ?俯在,一起交流學(xué)習(xí)!
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
// Override point for customization after application launch.
//實例化一個Window
self.window= [[UIWindowalloc]initWithFrame:[UIScreenmainScreen].bounds];
self.window.backgroundColor= [UIColorwhiteColor];
//設(shè)置成為主Window并顯示—重要
[self.windowmakeKeyAndVisible];
//實例化TabBar
MainTabBarController*tabBar = [[MainTabBarControlleralloc]init];
//將標簽控制器設(shè)置為根視圖控制器ps:iOS 9.0之后不設(shè)置rootViewController會crash
self.window.rootViewController= tabBar;
returnYES;
}
- (void)viewDidLoad {
[superviewDidLoad];
// Do any additional setup after loading the view.
//創(chuàng)建一個可變數(shù)組并初始化
NSMutableArray*mArr = [NSMutableArrayarray];
//循環(huán)創(chuàng)建4個控制器
for(inti =0; i <4; i ++) {
//實例化視圖控制器
BaseViewController*vc = [[BaseViewControlleralloc]init];
//設(shè)置視圖的背景顏色
vc.view.backgroundColor= [UIColorcolorWithRed:arc4random() %10*0.1green:arc4random() %10*0.1blue:arc4random() %10*0.1alpha:1];
//設(shè)置名稱
vc.title= [NSStringstringWithFormat:@"第%d個控制器",i +1];
//實例化導(dǎo)航控制器并初始化
MainNavigationController*nav = [[MainNavigationControlleralloc]initWithRootViewController:vc];
//添加視圖控制器到數(shù)組
[mArraddObject:nav];
}
self.viewControllers= mArr;
}
程序運行結(jié)果:
Keep It Simple, Stupid!
Keep It Simple, Stupid!
Keep It Simple, Stupid!