Often we are stuck when we are creating a default UITabbar project
and we need to add a login screen before it.
Quick Fix:
Declare and initialize two VC in AppDelegate.h
@property (strong, nonatomic) LoginVC* _loginVCObj;
@property (strong, nonatomic) UITabBarController *_tabBarController;
one for loginVC and one for otherVC (for default tabbar) in appDelegate and
On launch make LoginVC as RootViewController
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{// declare LoginVC and make it rootViewController
self.window.rootViewController = self._loginVCObj;
[self.window makeKeyAndVisible];
}
After login is successful call the function declared in AppDelegate class in LoginVC as
AppDelegate* appDelegateObj = (AppDelegate*)[[UIApplication sharedApplication] delegate];
[appDelegateObj continueToNextView];
In AppDelegate define the function as:
#
pragma mark- Continue to next screen after successful Login-(void) continueToNextView
{ // Handle UI after Login like.
[_loginVCObj._indicator stopAnimating];
[_loginVCObj._loginButton setEnabled:YES];
self._tabBarController = [[UITabBarController alloc]init];
//adding the VCs to the tabbar // set the viewControllers declared in the array, we can also use navigationController
self._tabBarController.viewControllers = [NSArray arrayWithObjects:myNavigationControllerList,_VC1Obj, _VC2Obj, _settingNavObj, nil];
// make tabbar as rootViewController
self.window.rootViewController = self._tabBarController;
}
Note In the above logic we have changed the rootview controller of the app Window.
No comments:
Post a Comment