2012-08-16 112 views
1

我有我我推從viewcontroller.testviewcontroller一個testviewcontroller已經後退按鈕和肯定button.when按下時使用在導航堆棧中找不到推動的視圖控制器?

[self.navigationController popViewControllerAnimated:YES]; 

按後退按鈕我要回以前的應用程序Yes按鈕我正在推動使用

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

另一個視圖控制器這是按下一個按鈕,我正在坡平當所有工作fine.in的rewardsget回testviewcontroller.using這個`

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

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

但是當我在該視圖中按後退按鈕它需要去我的新推視圖控制器,即rewardsget.But當我打印視圖控制器它不存在於stack.so它再次回來到第一個推動視圖控制器,不是最新的。任何人都可以幫助我呢?

+0

嘗試在你的循環內添加NSLog,你的循環是否執行? – janusbalatbat 2012-08-16 05:40:20

+0

ya它的工作。這不是問題。當我在後退按鈕中打印viewcontrollers它不是打印rewardsget.that我已經push.thats問題。 – hacker 2012-08-16 05:44:22

+0

@bugfinder我認爲你採取了本地變量;所以它在功能/方法失效時被釋放;所以儘量提供屬性合成並檢查一次; – alishaik786 2012-08-16 05:48:55

回答

0

聽起來好像您的堆棧中有多個TestViewController實例。要得到正確的只是一個指針TestViewController傳遞給你的GettingViewController,你可能希望有一個屬性:

@property (nonatomic, assign) TestViewController* testViewController;

當你準備回到你TestViewController通話[self.navigationController popToViewController: self.testViewController animated: YES];

這就是說,這聽起來像你的導航流可能需要一些更多的想法。在iOS上,中心輻射式導航流程是最自然的。

0

在for for循環中,您將瀏覽所有viewControllers,但已經假裝它們是TestViewController(TestViewController * vc ...)。當然,您正在尋找的第一個是KindOfClass TestViewController!

嘗試將其更改爲UIViewController * vc!

相關問題