简体   繁体   中英

Pushed View controller is not found in the navigation stack?

I have an application in which i am pushing a testviewcontroller from a viewcontroller.testviewcontroller has a back button and a yes button.when pressing the back button i am going back to the previous by using

[self.navigationController popViewControllerAnimated:YES];

when pressing the Yes button i am pushing another view controller using

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

this are all working fine.in the rewardsget when pressing a button i am poping back to testviewcontroller.using this `

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

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

but when i am pressing the back button in that view it needs to go to my new pushed view controller ie rewardsget.But when i am printing the view controllers it is not present in the stack.so it is again going back to the first pushed viewcontroller,not the latest.can anybody help me on this?

It sounds like you have multiple instances of TestViewController in your stack. To get to the correct one just pass a pointer to TestViewController to your GettingViewController, you may want to have a property:

@property (nonatomic, assign) TestViewController* testViewController;

When you're ready to go back to your TestViewController call [self.navigationController popToViewController: self.testViewController animated: YES]; .

That said, it sounds like your navigation flow may need some more thought. On iOS a hub-and-spoke navigation flow is the most natural.

in your for loop you go through all the viewControllers but already pretend that these are TestViewController (TestViewController*vc ...). Of course the first one you are looking for isKindOfClass TestViewController then!

Try changing this to UIViewController*vc!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM