xcode 选项卡控制器视图之前的 IOS 登录屏幕

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9174154/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 23:14:59  来源:igfitidea点击:

IOS login screen before tab-controller view

xcode

提问by Jin-Aurora

I am still newbie for IOS Developing, i want to create a login page by MoralViewcontroller.

我还是 IOS 开发的新手,我想通过 MoralViewcontroller 创建一个登录页面。

AppDelegate.h

AppDelegate.h

@interface AppDelegate : UIResponder <UIApplicationDelegate>{

     UITabBarController *tabBarController;   }

@property (nonatomic,retain) IBOutlet UITabBarController * tabBarController

AppDelegate.m

AppDelegate.m

(void)applicationDidFinishLaunching:(UIApplication *)application
{    
  // Override point for customization after app launch 

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

  [tabBarController.view presentModelViewcontroller: loginView animated:YES];

}

However, the login view cannot be shown, I think I define wrongly for tabBarController, but I don't know what wrong with it. Can anyone please advise me? I am doing IOS 5.

但是,无法显示登录视图,我认为我对tabBarController 定义错误,但我不知道它有什么问题。任何人都可以给我建议吗?我正在做 IOS 5。

Thanks alot..

非常感谢..

回答by Krrish

I'd present a loginView controller from the rootView of the tabBarController.

我会从 tabBarController 的 rootView 显示一个 loginView 控制器。

-(void)viewDidLoad
{
   //You can also do this inside a conditional statement, if needed
   LoginViewController *loginView=[[LoginViewController alloc]initWithNibName:@"LoginViewController" bundle:nil];

[self.view presentModelViewcontroller:loginView animated:YES];

}

And here is the second way

这是第二种方式

AppDelegate.h

AppDelegate.h

@interface AppDelegate : UIResponder {

 LoginViewController *loginView;  
}

@property (nonatomic,retain) LoginViewController *loginView;

AppDelegate.m

AppDelegate.m

-(void)applicationDidFinishLaunching:(UIApplication *)application 
{
// Override point for customization after app launch
self.loginView=[[LoginViewController alloc]initWithNibName:@"LoginViewController" bundle:nil];
[window addSubview:loginView. view];
[window makeKeyAndVisible];

}

LoginViewController.m

登录视图控制器.m

Call this method on successful login.

成功登录时调用此方法。

-(IBAction)login:(id)sender
{
//init tabbar with subviews;
    UITabBarController *tabBarController = [[UITabBarController alloc] initW....];
    [self.view addSubview:tabBarController.view];
}

I prefer first method, because in that you will be retaining the tabBarController in AppDelegate.

我更喜欢第一种方法,因为这样您将在 AppDelegate 中保留 tabBarController。

回答by Tendulkar

First of all you have to add the Loginviewcontroller to the window.And then you have to add the tabbarcontroller to the LoginViewController when the login button clicked.

首先,您必须将 Loginviewcontroller 添加到窗口。然后您必须在单击登录按钮时将 tabbarcontroller 添加到 LoginViewController。