码迷,mamicode.com
首页 > 移动开发 > 详细

IOS页面跳转的方法

时间:2015-03-02 18:20:28      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:

在页面跳转时,若想用pushViewController,则必须在AppDelegate设置UINavigationController,否则pushViewController无效。
并且用pushViewController从A跳往B后,在B页面自带“Back”按钮返回上一页。类似于

技术分享

这样设置,在AppDelegate中

 1 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
 2     self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen] bounds]];
 3     UIViewController *controllerA = [[ViewController alloc]init];
 4     UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:controllerA];
 5     
 6     self.window.rootViewController = nav;
 7     [self.window makeKeyAndVisible];
 8     
 9     return YES;
10 }

在controllerA中的跳转页面方法中这样写

-(void)turnToOtherController{
    ControllerB *controllerB = [[ControllerB alloc]init];
    [self.navigationController pushViewController:controllerB animated:YES];
}

这样,导航条就会一直存在。若不想要导航条,那么在AppDelegate这样写

1 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
2     self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen] bounds]];
3     UIViewController *controllerA = [[ViewController alloc]init];
4     self.window.rootViewController = controllerA;
5     [self.window makeKeyAndVisible];
6     
7     return YES;
8 }

而下面这种方法是通用的,无需设置rootViewController。

[self presentViewController:mainView animated:YES completion:nil];//controller自带的属性

下面的则需要

[self.navigationController pushViewController:mainView animated:YES];
//必须在AppDelegate设置UINavigationController,否则pushViewController无效。
//并且使用pushViewController后,在B页面,会自带一个“Back”按钮返回上一页。

 

IOS页面跳转的方法

标签:

原文地址:http://www.cnblogs.com/Apologize/p/4309130.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!