zoukankan      html  css  js  c++  java
  • ios NavigationViewController跳转以及返回传值


    (一)使用NavigationViewController进行页面跳转时,应该使用pushViewController方法来跳转至下一页面。这种话。下一页面相同在NavigationViewController容器中。

    1、跳转到下一页面:

    PowerViewController *power = [[PowerViewController alloc] init];

    //所要跳转页面PowerViewController中有个属性dictionary1是个NSMutableDictionary类型的容器
    [power.dictionary1 setObject:[self.outTxtPass text] forKey:ALONE_SITEPRIZE_PWD];
    //使用pushViewController跳转到下一页面
    [self.navigationController pushViewController:power animated:YES];

    ?

    2、从当前页面返回到上一页面并传值过去:

    //此页面已经存在于self.navigationController.viewControllers中,而且是当前页面的前一页面  

    PowerViewController *power = [self.navigationController.viewControllers objectAtIndex:self.navigationController.viewControllers.count-2];
    //初始化其属性
    power.dictionary = nil;
    //传递參数过去
    power.dictionary = [NSMutableDictionary dictionaryWithDictionary:self.dictionary1];
    //使用popToViewController返回并传值到上一页面
    [self.navigationController popToViewController:power animated:YES];
    返回到上一页后,上一页面显示后要接收參数,并刷新。

    注意此时应该在viewDidAppear中进行推断并接收传递的值:

    -(void)viewDidAppear:(BOOL)animated
    {
      //推断并接收返回的參数
     
    }

    3、从当前页面返回到上一页面(无需传值)的方法:
    //返回到上一界面
    -(IBAction)backOff:(id)sender
    {
        [self.navigationController popViewControllerAnimated:true];
    }


    (二)关于ios中 viewcontroller的跳转问题。当中有一种方式是採用navigationController pushViewController 的方法,比方我从主页面跳转到了一级页面,又从一级页面跳转到了二级页面。然后从二级页面跳转到了三级页面,依次类推。假设一级一级的返回我知道是没有问题的。调用navigationController popViewControllerAnimated即可了。

    可是某些情况下我可能想要立即回到主页面,而不是一级一级的返回(假设有非常多层会非常累的),那该怎么办呢?

    1.返回根页面vc用 

    [self.navigationController popToRootViewController]

    2.返回根页面vc用 :

    [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:2] animated:YES];

    或(通过class定位)

    for (UIViewController *controller in self.navigationController.viewControllers) {
        if ([controller isKindOfClass:[TargetController class]]) {
            [self.navigationController popToViewController:controller animated:YES];
        }
    }



  • 相关阅读:
    剑指 Offer 22. 链表中倒数第k个节点
    剑指 Offer 21. 调整数组顺序使奇数位于偶数前面
    Leetcode1450. 在既定时间做作业的学生人数
    Leetcode1572. 矩阵对角线元素的和
    Leetcode 1480. 一维数组的动态和
    Idea连接数据库报错
    Java实现二叉树层次遍历并存入List的方法:从上往下,从左往右
    SpringCloud资源网站
    Java循环对list进行remove
    Java中字符串判空的正确打开方式
  • 原文地址:https://www.cnblogs.com/wzzkaifa/p/7246498.html
Copyright © 2011-2022 走看看