I have a vc called ViewControllerOne
, when the user taps a UITableViewCell
I call a push segue
and navigate to ViewControllerTwo
. In ViewControllerTwo
I'm hiding the navigation bar, therefore I've created a custom back button:
- (IBAction)backBttn:(id)sender {
[self.navigationController popViewControllerAnimated:YES];
}
that works perfectly, but the viewDidLoad
getting called (in ViewControllerTwo
) every time I navigate back to ViewControllerOne
and than open ViewControllerTwo
again. Am I right that viewDidLoad
getting called because I'm using [self.navigationController popViewControllerAnimated:YES]
? Or it must have another reason?
If I understand you right you are seeing viewDidLoad called on the view controller you are pushing to. ( ViewControllerTwo
). If you push from ViewControllerOne
to ViewControllerTwo
, ViewControllerTwo
's viewDidLoad is being called.
If you then click the back button to pop ViewControllerTwo
, return to ViewControllerOne
, then push to ViewControllerTwo
again, you see viewDidLoad
being called a second time.
This is expected behavior. Push segues (and all other segues except unwind segues) create a new instance of the view controller they are presenting.
Likewise, popping/dismissing deallocates the view controller you are leaving.
When you pop the view controller from the navigation stack, the view that it manages is deallocated (or unloaded). Therefore, when you open ViewControllerTwo
again, the view must be loaded again. This is why viewDidLoad
is called multiple times in your case.
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.