简体   繁体   English

在选项卡控制器视图之前显示登录屏幕

[英]Show login screen before tab-controller view

i have a tabBarController application and using .xib files for the interface not the storyboard i have this code by default in the appdelegate 我有一个tabBarController应用程序,并且使用.xib文件作为界面而不是情节提要我默认在appdelegate中有此代码

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UIViewController *viewController1 = [[PopAdsFirstViewController alloc] initWithNibName:@"PopAdsFirstViewController" bundle:nil];

UIViewController *viewController2 = [[PopAdsSecondViewController alloc] initWithNibName:@"PopAdsSecondViewController" bundle:nil];

self.tabBarController = [[UITabBarController alloc] init];

self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, nil];

self.window.rootViewController = self.tabBarController;

[self.window makeKeyAndVisible];

return YES;

i have created a Login View and don't know how to show it before the tabBarView and hide t after a successful login. 我创建了一个登录视图,不知道如何在tabBarView之前显示它,并在成功登录后隐藏t。

One way would be to show it as a modalView on launch. 一种方法是在启动时将其显示为modalView。 Dismissing upon successfull login? 成功登录后退出吗? eg: 例如:

UIViewController myLoginViewController = [[MyLoginViewController alloc] init withNibNamed:"MyLoginViewController"]; //Or whatever you instantiation is
[myTabViewController presentModalViewController:myLoginViewController animated:YES];

And to dismiss it (Hide it) 并将其关闭(隐藏)

//This should be done from the original View Controller i.e. myTabViewController preferably in a delegate called by the modal view controller.
[self dismissModalViewControllerAnimated:YES];

Documentation on modalViewControllers: http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html 有关modalViewControllers的文档: http : //developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html

The way that I did it for one of my apps is to just add them in the correct order. 我为其中一个应用程序执行此操作的方法是,仅以正确的顺序添加它们。 Add your tabbar controller to your window, then add the login controller over the top of the tab bar. 将标签栏控制器添加到窗口,然后在标签栏顶部添加登录控制器。 Then show your window. 然后显示您的窗口。 The user won't see anything but your login controller. 除了您的登录控制器,该用户什么都看不到。 Once you login, you can just remove the login controller from view. 登录后,您只需从视图中删除登录控制器即可。

This way is probably best if you have information you need to hide until login. 如果您有需要隐藏直到登录的信息,这种方式可能是最好的。 The other way is to only launch the login view only. 另一种方法是仅启动登录视图。 On successful login, remove the login and add the tab bar controller. 成功登录后,删除登录并添加标签栏控制器。 Either way is fine. 两种方法都可以。

Presenting modally is probably the easiest, but requires a view in place before presenting. 模态演示可能是最简单的,但是在演示之前需要有适当的视图。 So if the data and view under the login controller isn't that sensitive, you could consider this option. 因此,如果登录控制器下的数据和视图不那么敏感,则可以考虑使用此选项。

Another way would be using LoginViewControllerDelegate in your appDelegate.h file 另一种方法是在appDelegate.h文件中使用LoginViewControllerDelegate

In your .h 在您的.h中

    #import "yourLoginViewController"
   //and add LoginViewControllerDelegate

Then in your .m 然后在您的.m中

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    yourLoginViewController *loginView = [[yourLoginViewController alloc] initWithNibName:@"yourLoginViewController" bundle:nil];
    loginView.delegate = self;
    [window addSubview:loginView.view];
    [window makeKeyAndVisible];
}
//add this one
- (void)loginViewControllerDidFinish:(yourLoginViewController *)loginViewController {
    [window addSubview:tabBarController.view];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM