繁体   English   中英

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

[英]Show login screen before tab-controller view

我有一个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;

我创建了一个登录视图,不知道如何在tabBarView之前显示它,并在成功登录后隐藏t。

一种方法是在启动时将其显示为modalView。 成功登录后退出吗? 例如:

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

并将其关闭(隐藏)

//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];

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

我为其中一个应用程序执行此操作的方法是,仅以正确的顺序添加它们。 将标签栏控制器添加到窗口,然后在标签栏顶部添加登录控制器。 然后显示您的窗口。 除了您的登录控制器,该用户什么都看不到。 登录后,您只需从视图中删除登录控制器即可。

如果您有需要隐藏直到登录的信息,这种方式可能是最好的。 另一种方法是仅启动登录视图。 成功登录后,删除登录并添加标签栏控制器。 两种方法都可以。

模态演示可能是最简单的,但是在演示之前需要有适当的视图。 因此,如果登录控制器下的数据和视图不那么敏感,则可以考虑使用此选项。

另一种方法是在appDelegate.h文件中使用LoginViewControllerDelegate

在您的.h中

    #import "yourLoginViewController"
   //and add LoginViewControllerDelegate

然后在您的.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