项目开始时 最初的框架搭建,代码写了一个简单的 包含 (UINavgationController,UITabBarController,UIViewController)的三级控制器界面 ,帮助新手更好的入门 开始程序的编写 , 如有不妥之处 ,欢迎提出意见 ,一起交流学习!
- (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];
//设置成为主Window并显示—重要
[self.windowmakeKeyAndVisible];
//实例化TabBar
MainTabBarController*tabBar = [[MainTabBarControlleralloc]init];
//将标签控制器设置为根视图控制器ps:iOS 9.0之后不设置rootViewController会crash
self.window.rootViewController= tabBar;
returnYES;
}
- (void)viewDidLoad {
[superviewDidLoad];
// Do any additional setup after loading the view.
//创建一个可变数组并初始化
NSMutableArray*mArr = [NSMutableArrayarray];
//循环创建4个控制器
for(inti =0; i <4; i ++) {
//实例化视图控制器
BaseViewController*vc = [[BaseViewControlleralloc]init];
//设置视图的背景颜色
vc.view.backgroundColor= [UIColorcolorWithRed:arc4random() %10*0.1green:arc4random() %10*0.1blue:arc4random() %10*0.1alpha:1];
//设置名称
vc.title= [NSStringstringWithFormat:@"第%d个控制器",i +1];
//实例化导航控制器并初始化
MainNavigationController*nav = [[MainNavigationControlleralloc]initWithRootViewController:vc];
//添加视图控制器到数组
[mArraddObject:nav];
}
self.viewControllers= mArr;
}
程序运行结果:
Keep It Simple, Stupid!
Keep It Simple, Stupid!
Keep It Simple, Stupid!