【问题标题】:Switching views in iOS在 iOS 中切换视图
【发布时间】:2012-08-24 09:01:34
【问题描述】:

我的故事板中有 3 个视图控制器,例如 Page1Page2Page3Page1Page2 都被推送到 Page3。我想要做的是当Page3点击后退按钮时,视图将 100% 返回到 Page1 并且永远不会返回到 Page2。我现在使用的代码是

[self.navigationController popViewControllerAnimated:YES];

什么会回到它来自的页面有什么办法吗?我想修复它返回的页面,但不弹回它的来源。

【问题讨论】:

  • 如果 Page1 是根目录,您应该使用[self.navigationController popToRootViewControllerAnimated:true]
  • 是的,这就是我想要的。非常感谢:)
  • ya.. 当然 :) 感谢您的帮助
  • 好的,我已经完成了……谢谢,不客气。 :)

标签: iphone view navigation


【解决方案1】:

你应该使用

[self.navigationController popToRootViewControllerAnimated:true];

如果 Page1 是根目录,它将非常适合您。

【讨论】:

    【解决方案2】:

    您应该创建带有后退按钮的自定义导航控制器,然后单击后退按钮编写我的代码以导航到 page 1

    .xib文件中拖一个导航栏并在上面放一个返回按钮,

    后退按钮上的代码 sn-p,

    -(void)BackButtonClick
    {
      YourView *Obj = [[YourView alloc] initWithNibName:@"YourView" bundle:nil];
      [self.navigationController popViewController:Obj animated:YES];
      [Obj release];
    }
    

    【讨论】:

      【解决方案3】:

      试试这个代码,

      - (NSArray *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated
      
       NSInteger currentIndex = [self.navigationController.viewControllers indexOfObject:self];
      if( currentIndex-2 >= 0 ) 
      {
         [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:currentIndex-2] animated:YES];
      }
      

      【讨论】:

      • currentIndex < 2 时会发生什么?用户会被卡住吗?
      猜你喜欢
      • 1970-01-01
      • 2011-11-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-07
      • 2023-03-27
      • 1970-01-01
      • 2011-01-08
      相关资源
      最近更新 更多