IOS AppDelegate设置Root页面
2015-09-19 16:35
357 查看
1.最简单的只有一个控制器的root页面(不用默认的storyrboard)
AppDelegate.m
#import "AppDelegate.h"
#import "KCMainViewController.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen] bounds]];
KCMainViewController *mainView = [[KCMainViewController alloc]initWithNibName:@"KCMainViewController" bundle:nil];
_window.rootViewController = mainView;
[_window makeKeyAndVisible];
return YES;
}
2.用Navigation设置的多个控制器的root页面
1)AppDelegate.h
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UINavigationController *navigationController;
@end
2)AppDelegate.m
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
self.window.backgroundColor = [UIColor whiteColor];
RegisterViewController *masterViewController = [[RegisterViewController alloc]initWithNibName:@"RegisterViewController" bundle:nil];
_navigationController = [[UINavigationController alloc]initWithRootViewController:masterViewController];
[_window addSubview:_navigationController.view];
[self.window makeKeyAndVisible];
}
这里多说点页面跳转的事情,如果用navigation,就是用代理的navigationController的pushViewController方法把新的controller放到导航的栈里,运用“后进先出”的原理,切换页面。
3.使用TabBar设置Root控制器
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
GGTabBarController *tabBar = [[GGTabBarController alloc] init];
TestViewController1 *vc1 = [[TestViewController1 alloc] init];
// vc1.tabBarItem.title = @"花时间";??
// vc1.tabBarItem.badgeValue = @"12";
TestViewController2 *vc2 = [[TestViewController2 alloc] init];
TestViewController3 *vc3 = [[TestViewController3 alloc] init];
tabBar.viewControllers = @[vc1, vc2, vc3];
self.window.rootViewController = tabBar;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
AppDelegate.m
#import "AppDelegate.h"
#import "KCMainViewController.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen] bounds]];
KCMainViewController *mainView = [[KCMainViewController alloc]initWithNibName:@"KCMainViewController" bundle:nil];
_window.rootViewController = mainView;
[_window makeKeyAndVisible];
return YES;
}
2.用Navigation设置的多个控制器的root页面
1)AppDelegate.h
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UINavigationController *navigationController;
@end
2)AppDelegate.m
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
self.window.backgroundColor = [UIColor whiteColor];
RegisterViewController *masterViewController = [[RegisterViewController alloc]initWithNibName:@"RegisterViewController" bundle:nil];
_navigationController = [[UINavigationController alloc]initWithRootViewController:masterViewController];
[_window addSubview:_navigationController.view];
[self.window makeKeyAndVisible];
}
这里多说点页面跳转的事情,如果用navigation,就是用代理的navigationController的pushViewController方法把新的controller放到导航的栈里,运用“后进先出”的原理,切换页面。
3.使用TabBar设置Root控制器
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
GGTabBarController *tabBar = [[GGTabBarController alloc] init];
TestViewController1 *vc1 = [[TestViewController1 alloc] init];
// vc1.tabBarItem.title = @"花时间";??
// vc1.tabBarItem.badgeValue = @"12";
TestViewController2 *vc2 = [[TestViewController2 alloc] init];
TestViewController3 *vc3 = [[TestViewController3 alloc] init];
tabBar.viewControllers = @[vc1, vc2, vc3];
self.window.rootViewController = tabBar;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
相关文章推荐
- Android Studio ------Dynamic layout preview
- oc键值监听
- Android中SQLite使用
- CSAPP Chapter 2
- Error: Error parsing D:\android-sdk-windows\sdk\system-images\android-22\android-wear\x86\devices.xm
- Android之SlidingMenu使用和总结
- android纯代码圆周动画
- UIWebView改变HTML中图片的大小,进行等比例缩放
- IOS9 QQ阿里微信跳转调整
- 【Xamarin 开发 IOS --IOS ViewController生命周期】
- android 切换主题实现
- android api ,谢谢阿里巴巴
- 利用观察者模式实现Cocos2DX-lua游戏中的消息管理系统
- @RequestMapping 用法详解之地址映射(转)
- [2015-09-19 15:07:13 - LinearLayoutActivity] Unable to resolve target 'android-14'
- 点评系统 Modoer v3.6 旗舰版手机WEB端加微信公众平台接口
- Android使用文件进行数据存储的方法
- 那两年炼就的Android内功修养
- 【Xamarin开发IOS-IOS生命周期】
- Android 中关于 【Cursor】 类的介绍