Home  >  Q&A  >  body text

ios - 如何让栈中的页面总是返回到固定页面?

项目中,有很多途径进入到我的订单中.如:

  1. 我(顶级页面)->我的订单

  2. 首页(顶级页面)->商品详情->支付->支付成功->我的订单.

但是需求是,从我的订单只能返回到的页面.即:

我的订单 -(back)->我

在这种需求下,如何来实现呢?

PHP中文网PHP中文网2741 days ago353

reply all(3)I'll reply

  • ringa_lee

    ringa_lee2017-04-18 09:27:34

    The following provides an idea, which can be modified according to your own project conditions

    Assume that your project has the architecture shown in the figure. You can add the following code to the order interface.

    
    
    - (void)viewDidAppear:(BOOL)animated {
        [super viewDidAppear:animated];
    
        UINavigationController *nav = self.tabBarController.viewControllers.lastObject;
        NSMutableArray *vcs = [NSMutableArray array];
        [vcs addObject:nav.viewControllers.firstObject];
        [vcs addObject:self];
        [nav setViewControllers:vcs animated:NO];
        [self.tabBarController setSelectedIndex:self.tabBarController.viewControllers.count-1];
    }
    

    reply
    0
  • 阿神

    阿神2017-04-18 09:27:34

    Method 1:

    //回到根视图
    navigationController?.popToRootViewControllerAnimated(animated: Bool)
    

    Method 2:

    //回到指定视图
    navigationController?.popToViewController(UIViewController, animated: Bool)
    
    

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-18 09:27:34

    Modal or whole pseudo-navigation

    reply
    0
  • Cancelreply