【问题标题】:Pushed View controller is not found in the navigation stack?在导航堆栈中找不到推送视图控制器?
【发布时间】:2012-08-16 05:35:53
【问题描述】:

我有一个应用程序,我在其中从 viewcontroller 推送 testviewcontroller。testviewcontroller 有一个后退按钮和一个是按钮。当按下后退按钮时,我将使用

返回上一个
[self.navigationController popViewControllerAnimated:YES];

当按下是按钮时,我正在使用另一个视图控制器

 GettingViewController *get  =[[GettingViewController alloc] initWithNibName:@"GettingViewController" bundle:nil];
 [self.navigationController pushViewController:get animated:NO];

这一切都很好。在按下按钮时的奖励中,我弹回 testviewcontroller。使用这个`

for (TestViewController*vc in [self.navigationController viewControllers]) {
            if ([vc isKindOfClass: [TestViewController class]]){

                 [[self navigationController] popToViewController:vc animated:YES];
            }
        }
`

但是当我在该视图中按下后退按钮时,它需要转到我的新推送视图控制器,即奖励获取。但是当我打印视图控制器时,它不存在于堆栈中。所以它再次回到第一个推送的视图控制器,不是最新的。有人可以帮我吗?

【问题讨论】:

  • 尝试在你的循环中添加 NSLog,你的循环执行了吗?
  • 它工作正常。这不是问题。当我在后退按钮中打印视图控制器时,它没有打印rewardget。我已经被推动了。这就是问题。
  • @bugfinder 我想你拿了局部变量;所以它在功能/方法失效时被释放;所以尽量提供属性综合,检查一次;
  • 如果您在点击奖励按钮时写上[self.navigationController popViewControllerAnimated:YES]; 会怎样?

标签: iphone ios ipad


【解决方案1】:

听起来您的堆栈中有多个 TestViewController 实例。要找到正确的,只需将指向 TestViewController 的指针传递给您的 GettingViewController,您可能需要一个属性:

@property (nonatomic, assign) TestViewController* testViewController;

当您准备好返回 TestViewController 时,调用 [self.navigationController popToViewController: self.testViewController animated: YES];

也就是说,听起来您的导航流程可能需要更多思考。在 iOS 上,中心辐射式导航流程是最自然的。

【讨论】:

    【解决方案2】:

    在您的 for 循环中,您遍历所有 viewController,但已经假装这些是 TestViewController (TestViewController*vc ...)。当然你要找的第一个就是KindOfClass TestViewController了!

    尝试将其更改为 UIViewController*vc!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多