SWRevealViewController之前的Login View控制器 [英] Login View controller before SWRevealViewController
问题描述
我遵循parse.com教程,以了解如果注册或登录成功,则如何实现登录+注册+对主控制器进行segue.这很漂亮.
I followed parse.com tutorials on how to implement login + register + segue to main controller if registration or login is successful. This works beautiful.
然后,我想使用SWRevealViewController实现侧面导航.我遵循了APPCODA链接,并且只有在"SWRevealViewController"是初始视图控制器时,它才起作用.
I then wanted to implement a side navigation using SWRevealViewController. I followed APPCODA link on this and got it working only when "SWRevealViewController" is the initial view controller.
当我将解析登录控制器作为初始名称时,我从导航控制器(即"SWRevealViewController")中看不到任何东西.
When i have my parse login controller as initial i can't see anything from the navigational controller aka "SWRevealViewController."
当登录/注册成功后,我将如何解决此问题,将我的登录/注册控制器设置为初始控制器,并且仍然能够拥有SWRevealViewController?
how would i be able fix this, make my login/register controllers the initial controllers and still be able to have SWRevealViewController when login/register is successful?
我将不胜感激任何帮助或指示.
i would appreciate any help or pointers.
下面是我的APPDelegate.m
below is my APPDelegate.m
#import "AppDelegate.h"
#import <Parse/Parse.h>
#import <GoogleMaps/GoogleMaps.h>
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
LoginView *lv = [[LoginView alloc]init];
SidebarViewController *sbvc = [[SidebarViewController alloc]init];
UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:lv];
UINavigationController *menuVC = [[UINavigationController alloc]initWithRootViewController:sbvc];
SWRevealViewController *revealController = [[SWRevealViewController alloc]initWithRearViewController:menuVC frontViewController:nav];
revealController.delegate = self;
self.menu = revealController;
self.window.rootViewController = self.menu;
[GMSServices provideAPIKey:@"XXXXXXXXXX"];
[Parse setApplicationId:@"XXXXXXXXXXXXX"
clientKey:@"XXXXXXXXXXXXX"];
[PFAnalytics trackAppOpenedWithLaunchOptions:launchOptions];
return YES;
}
推荐答案
在具有用户会话的应用中,通常最好将登录/注册与应用的其余部分保持在单独的视图层次结构中,并在其中显示内部结构是一个活跃的会话.您可以通过检查
In apps with user sessions, it is usually best to keep login/signup on a separate view hierarchy from the rest of the app and present the internal structure if there is an active session. You can achieve this by checking for
[PFUser currentUser]
,因为如果用户未登录,它将返回nil
.
as it will return nil
if the user is not logged in.
像这样在您的AppDelegate中提供支票:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// .. Rest of your initialization code
if ([PFUser currentUser]) {
// Let's pop them right to the home screen
[self showHomeScreen];
}
else {
// Present login vc
LoginView *lv = [[LoginView alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:lv];
self.window.rootViewController = nav;
}
return YES;
}
- (void)showHomeScreen {
SidebarViewController *sbvc = [[SidebarViewController alloc] init];
UINavigationController *menuVC = [[UINavigationController alloc] initWithRootViewController:sbvc];
UIViewController *home = [[UIViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:home];
SWRevealViewController *revealController = [[SWRevealViewController alloc] initWithRearViewController:menuVC frontViewController:nav];
self.window.rootViewController = revealController;
}
然后,通过添加
- (void)showHomeScreen;
在AppDelegate.h
中,您可以在成功注册/登录后调用此方法:
in AppDelegate.h
, you can call this method upon successful registration/login:
AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[delegate showHomeScreen];
这篇关于SWRevealViewController之前的Login View控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!