ios中的视图跳转方式

2016-08-04  本文已影响439人  朱益达

16/08/04/wed

iOS视图跳转的方式

1.使用modal方式进行跳转

-(void)login{
    KCLoginViewController *loginVC=[[KCLoginViewController alloc]init];
    //调用此方法显示窗口
    [self presentViewController:loginVC animated:YES completion:nil];
}
===============================================================================
//如果想要在modal下一个控制器的时候销毁当前控制器,可以把主窗口的根控制器设置为modal 出的控制器,代码如下:
    BViewController *bvc = [[BViewController alloc] init];
    [self presentViewController:bvc animated:YES completion:nil];
    [UIApplication sharedApplication].keyWindow.rootViewController = bvc;

2.使用导航控制器进行跳转

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    _window=[[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    
    _window.backgroundColor =[UIColor colorWithRed:249/255.0 green:249/255.0 blue:249/255.0 alpha:1];

    KCFriendViewController *friendVC=[[KCFriendViewController alloc]init];
    
    UINavigationController *navigationController=[[UINavigationController alloc]initWithRootViewController:friendVC];
    
    _window.rootViewController=navigationController;
    
    [_window makeKeyAndVisible];
    
    return YES;

3.通过UITabBarcontroller进行跳转

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    _window=[[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    
    KCTabBarViewController *tabBarController=[[KCTabBarViewController alloc]init];
    
    KCWebChatViewController *webChatVC=[[KCWebChatViewController alloc]init];
    KCContactViewController *contactVC=[[KCContactViewController alloc]init];
    tabBarController.viewControllers=@[webChatVC,contactVC];
    //注意默认情况下UITabBarController在加载子视图时是懒加载的,所以这里调用一次contactVC,否则在第一次展示时只有第一个控制器tab图标,contactController的tab图标不会显示
    for (UIViewController *controller in tabBarController.viewControllers) {
        UIViewController *view= controller.view;
    }
    _window.rootViewController=tabBarController;
    [_window makeKeyAndVisible];
    
    return YES;
}
上一篇 下一篇

猜你喜欢

热点阅读