Define the first time a UIViewController appears

Prior to resorting to custom flags, I wanted to check it out with you people.

Is there a built-in way to determine in viewWillAppear: or viewWillDisappear: that the UIViewController is "recently pushed" onto the UINavigationController stack, or did the navigation controller pop out another view by showing it? I want to execute one-time code the first time I view a view. Since the self.bounds property must be set, the viewDidLoad: method viewDidLoad: not suitable.

I was hoping to get some results with what I use to define something like this on viewWillDisappear: but in the first viewWillAppear: index is already set to 1:

 [self.navigationController.viewControllers indexOfObject:self] 

So this is a useless fragment. Any ideas?

+4
source share
2 answers

The way that I handle this is the following: to have a flag that is initially set to false, when you press the child view controller on your navigation controller, set this flag to true, no on viewDidAppear, if the flag is false then this is the initial load, if true, then it returns from the child controller that drops out of the navigation stack.

+3
source

There is no built-in verification method. This is a detailed discussion about your request.

-1
source

All Articles