show a login screen before Tab bar controller?

我们两清 提交于 2019-12-17 20:40:36

问题


i am designing an iphone application which should be display login screen initially, after that it should display tab bar controller with 5 tabs. Am able to launch login screen initially, but after that am unble to show tab bar controller, kindly help me out with the source code guys. here is my code: this is a view based application

application.M

 -(void)applicationDidFinishLaunching:(UIApplication *)application {    

    // Override point for customization after app launch 
       [window addSubview:viewController.view]; 
    [window addSubview:tabBarController. view];   
    [window makeKeyAndVisible];
    LoginView *loginView=[[LoginView alloc]initWithNibName:@"LoginView" bundle:nil];
    [window addSubview:loginView.view];
}  

by doing this the tab bar controller is displaying at the bottom of the login screen initially.And also am unable to switch between the tab bar items.


回答1:


What you can do is the following.

Launch the Tabbar as the main screen and then before the view is loaded or displayed show the logon screen and dismiss the logon screen after successful log on.

EDIT: For a code example look at code provided by Maulik




回答2:


Try to do the following:

[window makeKeyAndVisible];
LoginView *loginView=[[LoginView alloc] initWithNibName:@"LoginView" bundle:nil];
[window addSubview:loginView.view];

You will want to show the loggin first. After the login done, you should send a message to your app delegate so he can switch between your login view and your tabBarController:

-(void)loginFinished{   
    window.rootViewController=tabBarController;
}

I advise you to:

1 - Have IBOutlets for your LoginViewController and UITabBarViewController, so you can easly use them.

2- Use a notifcation, so your app delegate knows when to switch the controllers.




回答3:


Assuming you have TabBarController class by sub classing UITabBarController.

You can also push tab bar controller after the Login view complete its job.

In Login.m file

- (void) doLogin
{
  if(login)
  {
     TabBarController *aTabBarController = [[TabBarController alloc] initWithNibName:@"TabBarController" bundle:nil];
     [self.navigationController pushViewController:aTabBarController animated:YES];
     [aTabBarController release];    
  }
}


来源:https://stackoverflow.com/questions/8504219/show-a-login-screen-before-tab-bar-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!