1

I want the view controller to check something, and if it's true it would allow the user to use the view controller, and if it's false it would show an alert to the user and send the user back where he/she came from.

So I tried adding this to an if-statement at the end of viewDidLoad:

[self.navigationController popViewControllerAnimated:YES]

However, I got the error:

2014-08-09 20:12:59.731 ProjectName[1978:60b] nested pop animation can result in corrupted navigation bar

2014-08-09 20:13:00.118 ProjectName[1978:60b] Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted.

I learned from this StackOverflow question that calling pushViewController or popViewController before viewDidLoad finishes is unsafe. Are there any ways around this?

TLDR: I'm trying to push a view controller onto the stack, show an alert, then pop the view controller off of the stack.

EDIT: Added code.

Community
  • 1
  • 1
Fares K. A.
  • 1,167
  • 5
  • 22
  • 45
  • How about `viewDidAppear:`? Also you could consider displaying the alert that explains to user what is going on and pop the controller _after_ the user dismisses the alert. – Alladinian Aug 09 '14 at 19:47

1 Answers1

2

This should be fairly easy provided you want to show the alert.

1 - Call [UIAlertView show] method from within viewDidAppear. It would be advisable to use viewDidAppear as it would be last in the view life cycle, when the view controller is fully pushed on the stack. So popping will be harmless.

2 - In clickedButtonAtIndex delegate method, call popViewControllerAnimated.

Nirav Bhatt
  • 6,682
  • 5
  • 39
  • 82