I am using a tab bar controller in my app but I load a login screen on top of the controller when the app first starts:
initialScreenViewController = [[Login alloc] init];
[window addSubview:tabBarController.view];
[window addSubview:initialScreenViewControl开发者_运维知识库ler.view];
[window makeKeyAndVisible];
return YES;
When the user successfully authenticates, I remove the login view:
[self.view removeFromSuperview];
This all works perfectly with one small exception. There are labels on the first tab of my tab bar controller that get populated based on what the user logs in with. However, since that view actually loads behind the login screen before the user has even authenticated, it doesn't appear correctly after authentication.
My question is this....is there a way to get the tab bar pages to some how "refresh" after login? Or perhaps not even load the tab bar controller until after login?
Thank you!! Jason
You could tackle this problem in a number of ways, but I think the simplest to understand and implement is to use a notification. Have your login view controller post a notification when the user has successfully logged in, and have any other view controller that cares about user authentication listen for that notification.
You want a fairly loose coupling between the login controller and anything else -- the view controllers that might change their content based on the user's status shouldn't have to know anything about the login controller in particular, and the login controller shouldn't have to know about all the other controllers that might be affected by a change in the user's status. Notifications provide that loose coupling, and they're easy to use.
精彩评论