user1085093
user1085093

Reputation: 507

How to switch between two view controllers

I have two UIViewControllers, vc1 and vc2.

I want to switch between them. But before loading the view of the new view controller, I want to destroy/release/remove (I'm not sure abt the correct word to use here) the previous viewcontroller.

For example, when I am switching to vc2 from vc1 ,I want to destroy vc1 completely, so that when I return to vc1 from vc2, vc1 will be loaded from scratch (i.e. viewDidLoad will be executed).

Which type of view switching should I opt for?

  1. presentModal...
  2. addSubview.

I am not using a navigation controller.

Currently I am using the presentModal... method, but when I use dismissModalViewcontroller on the newly presented view controller, it doesn't show up a new instance of the previous view controller. Instead, it shows the already running instance of it.

I want the viewDidLoad method of the previous view controller to run when I dismiss the newly presented view controller.

Upvotes: 0

Views: 2468

Answers (2)

XJones
XJones

Reputation: 21967

See this answer. You can do this with or without animation.

Animate change of view controllers without using navigation controller stack, subviews or modal controllers?

Upvotes: 0

Carlton Gibson
Carlton Gibson

Reputation: 7386

What exactly needs to happen in viewDidLoad?

You also have viewWillAppear available to you, so it could be that you could move the required functionality there and still use the modal presentation.

Upvotes: 1

Related Questions