zoukankan      html  css  js  c++  java
  • IOS页面跳转的方法

    在页面跳转时,若想用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”按钮返回上一页。
  • 相关阅读:
    arcgis server10.2自带打印模板路径
    【js笔记】数组那些事[0]
    微信打开网页不能下载的解决
    CSS里一个奇怪的属性
    存一些有用的CSS
    【JS笔记】闭包
    关于百度空间的关闭
    数据校验插件开发
    JavaScript 内存机制
    手写JQuery 的框架的实现
  • 原文地址:https://www.cnblogs.com/Apologize/p/4309130.html
Copyright © 2011-2022 走看看