tyler
tyler

Reputation: 1

viewWillAppear only being called once

Here's the scenario, switchViewController is the view added to the main window. So switchViewController is the main view, so if I want to go view B, I will addsubview of view B, there isn't a need to remove switchViewController's view right? The issue is after I go back from view B to switchViewController's view, the method viewWillAppear is not being called anymore.

Why is it so?

Upvotes: 0

Views: 1270

Answers (3)

DVG
DVG

Reputation: 17470

It's not getting called beause your just modifying the first view, not navigating to a different one.

You might consider embedding your view in a Navigation controller, then calling your ViewB with

[navigationController pushViewController:viewB animated:YES];

Upvotes: 0

Ole Begemann
Ole Begemann

Reputation: 135588

viewWillAppear: is not called automatically when a view is removed from or added to the view hierarchy. It is the responsibility of the view controller to call it at the right time. The built-in view controller classes do this whenever you present or push a new view controller. Since you do not use this mechanism in your app, the method doesn't get called (unless you call it yourself).

Upvotes: 2

Jim
Jim

Reputation: 73966

That's because it never disappeared, you were just putting something else in front of it. If you want to navigate from one screen to another and back, they should be separate view controllers, and you should be using UINavigationController and its pushViewController:isAnimated: method.

Upvotes: 1

Related Questions