UINavigationController popViewController pops up everything!

So, I'm trying to pull the view controller out of the stack when an error occurs, but it seems to pop too much at a time. The navigation bar at the top loses its name and buttons, but the old table view data remains visible. I have no idea what's going on ...

Basic setting:

  • Tab Pattern
    • Navigation controller
      • View controller (downloaded from xib)
      • View controller (clicked that I want to pop)

Here is the code:

NSLog(@"%@", [[self navigationController] viewControllers]);
[[self navigationController] popViewControllerAnimated:NO];
NSLog(@"%@", [[self navigationController] viewControllers]);

As a result, NSSC will show:

2009-09-22 19:57:14.115 App[34707:550b] (
    <MyViewController: 0xd38a70>,
    <MyViewController: 0xd36b50>
)
2009-09-22 19:57:14.115 App[34707:550b] (null)

Does anyone have any experience?

+3
source share
4 answers

I see some odd stack behavior UINavigationControllerwhen using

[self.navigationController popViewControllerAnimated:YES];

, tableView:didSelectRowAtIndexPath:.

, UINavigationController "" , .

,

[self.navigationController popToViewController:self animated:YES];

. ARC.
, , , , , , "unreferenced" .

+4
[[self navigationController] popViewControllerAnimated:NO];
//here you pop **self** from navigation controller. And now 
[self navigationController] == nil;   
// And 
[nil viewControllers] == nil

:

UINavigationController *nc = [self navigationController];
NSLog(@"%@", [nc viewControllers]);
[nc popViewControllerAnimated:NO];
NSLog(@"%@", [nc viewControllers]);
+1

I fixed it. The code displaying the view was called in viewDidLoad. This meant that he was pushed out before the performance really came to life.

I moved this code to viewDidAppear and now it works as advertised.

+1
source

What's wrong?

[self.navigationController popViewControllerAnimated:NO];

In addition, you can check how you push ViewControllerthe stack. Something doesn't sound right.

0
source

Source: https://habr.com/ru/post/1718268/


All Articles