Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS

Kevin Fricke
Kevin Fricke
3,117 Points

process for logging users out

I have an application that I am building that is doing a ton of stuff when the views load. Is there a method that I can use to reload all of the views when a user logs out so that all of the viewDidLoad content is reloaded?

Primarily this is an issue because I am using the JASidePanel 'plugin' and if I log out and log back in the content is not refreshed for the new user. Thoughts?

Thanks in advance....

4 Answers

Stone Preston
Stone Preston
42,016 Points

one solution is to move that code into viewDidAppear and use a BOOL property (self.refresh for example) to control whether or not it needs to be refreshed or not.

so whenever you log the user out, set that refresh BOOL variable to YES.

- (void)logout {
    [PFuser logout]
    self.refresh = YES;
}

in viewDidAppear you could have something like this:

   if (self.refresh == YES) {

        self.refresh = NO;
        //newly logged in user
       //perform the setup of the view for that new user

} else {

     //refresh is not necessary
}
Kevin Fricke
Kevin Fricke
3,117 Points

I am also setting an array that is populating a table view. When I move that array to viewDidAppear the table is not loaded....

Kevin Fricke
Kevin Fricke
3,117 Points

I can. I am reluctant too because it may ALL be garbage....still learning. I can clean it up and send. Quick question though. Are you familiar with JASidePanel? Getting that to reload is the real issue...

Is there a way to logout and reset all of the views so that once you login it will re-run the viewDidLoad methods again?

Stone Preston
Stone Preston
42,016 Points

the only way would be to destroy all your views (but im not sure thats good practice) I still think your best option is to either use viewWillAppear, or use the notification center to send notifications to your views when login and logouts occur that run your code then.

Kevin Fricke
Kevin Fricke
3,117 Points

The notifications might be the best bet. There was only one example that I remember when I was folloing the ios track. Do you have any good resources for that.

Bottom line, what I am trying to do is to load some data and store it as userDefaults (or the appropriate alternative) in the panel. We have a list of teams there. If you logout and log back in I need those list of teams to be for the current user...not the last user. Notifications are probably the way to go for me.

Thanks for the help!