ios导航实现页面切换

来源:互联网 发布:截图软件下载 编辑:程序博客网 时间:2024/04/29 08:13

1.在AppDelegate.m实现的事件代码,用UINavigationController来进行页面之间的切换

 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

    self.window =[[UIWindowallocinitWithFrame:[[UIScreenmainScreen]bounds]];

    self.window.backgroundColor=[UIColorwhiteColor];

    rootView * r=[[rootViewalloc]init];

    UINavigationController * nav=[[UINavigationControlleralloc]initWithRootViewController:r];

    self.window.rootViewController=nav;

    [self.windowmakeKeyAndVisible];

returnYES;

}

2.用tab bar 来切换view

对应的按钮事件

-(IBAction)btnTab

{

    UITabBarController* tabBarController = [[UITabBarControlleralloc]init];

first *firstViewController = [[firstalloc] initWithNibName:nilbundle:nil];

UINavigationController *firstNavigationController = [[UINavigationControlleralloc] initWithRootViewController:firstViewController];

    [firstNavigationController setNavigationBarHidden:YESanimated:YES];

    [firstNavigationController setTitle:@"第一视图"];

 

second *secondViewController = [[secondalloc] initWithNibName:nilbundle:nil];

UINavigationController *secondNavigationController = [[UINavigationControlleralloc] initWithRootViewController:secondViewController];

    [secondNavigationController setNavigationBarHidden:YESanimated:YES];

    [secondNavigationController setTitle:@"第二视图"];

    

    third *thirdViewController = [[thirdalloc] initWithNibName:nilbundle:nil];

UINavigationController *thirdNavigationController = [[UINavigationControlleralloc] initWithRootViewController:thirdViewController];

    [thirdNavigationController setNavigationBarHidden:YESanimated:YES];

    [thirdNavigationController setTitle:@"第三视图"];

    

    forth *forthViewController = [[forthalloc] initWithNibName:nilbundle:nil];

UINavigationController *forthNavigationController = [[UINavigationControlleralloc] initWithRootViewController:forthViewController];

    [forthNavigationController setNavigationBarHidden:YESanimated:YES];

    [forthNavigationController setTitle:@"第四视图"];

 

tabBarController.viewControllers = [NSArrayarrayWithObjects:firstNavigationController,secondNavigationController,thirdNavigationController,forthNavigationController,nil];

tabBarController.modalTransitionStyle=UIModalTransitionStyleCoverVertical;       

    

    [selfpresentModalViewController:tabBarControlleranimated:YES];

    }


原创粉丝点击