Rocky
Rocky

Reputation: 289

iPhone: Restart the app after clicking on a button?

My app has a logout button and when the user hits that button, I need to kill all the existing views and background tasks (though I don't want to see the launch image again).

How can I accomplish this?

Upvotes: 2

Views: 622

Answers (2)

Kenrik March
Kenrik March

Reputation: 379

The way I usually handle this is to have the LoginViewController be the RootViewController of the app with a NavigationController. On the LoginController I set the NavigationBar to be hidden.

Then it's just a simple.

[self.navigationController popToRootViewControllerAnimated:NO];

And all of your views are gone/killed (if you built them properly) so you'll only have to handle killing off any background processes that are not managed by the views.

Upvotes: 1

Gabriele Petronella
Gabriele Petronella

Reputation: 108091

In order to kill the views, just change the rootViewController property of the window.

Something like

self.window.rootViewController = //The new view controller to be presented here

In order to kill the background tasks it depends on the nature of the tasks. If you have a reference to them, you can kill them manually when logging out.

Upvotes: 0

Related Questions