我在我的应用程序中使用RESideMenu。但我需要在RESideMenu之前添加登录和注册视图控制器。
是否可能,如果是,那我该怎么做?
提前致谢。
答案 0 :(得分:0)
有很多方法可以做到这一点。最常见的是你有一个loginView控制器,然后在app delegate中你可以在app delegate中写这样的东西:
if([[NSUserDefaults standardUserDefaults] valueForKey:@"AlreadyLogin"])
{
// So, here user already login then set your root view controller, let's say `SecondViewController``
SecondViewController *secondViewController = [storyBoard instantiateViewControllerWithIdentifier:@"SecondViewController"];
// then set your root view controller
self.window.rootViewController = secondViewController;
}
else
{
// It means you need to your root view controller is your login view controller, so let's create it
LoginViewController *loginViewController= [storyBoard instantiateViewControllerWithIdentifier:@"LoginViewController"];
self.window.rootViewController = loginViewController;
}
答案 1 :(得分:0)
是的,很有可能。
解决方案A:
成功登录/注册后,请执行以下操作:
[UIApplication sharedApplication].window.rootViewController = [[RESideMenu alloc] init...];
解决方案B:
将您的登录/注册视图控制器放在RESideMenu
的主要内容部分中,并禁用两个侧面菜单,直到用户登录。
解决方案C:
将RESideMenu
嵌入UINavigationController
并可选择隐藏导航栏。
有关详细信息,我建议研究"查看控制器控制"因为这是RESideMenu
,UINavigationController
和其他类型的"容器"使用的模式。查看控制器。
我将解决方案C的一个快速示例拼凑在一起,它似乎工作正常:
@implementation LoginViewController
- (void)viewDidLoad {
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(50, 50, 100, 100);
[button setTitle:@"Login" forState:UIControlStateNormal];
[button addTarget:self action:@selector(goToRESideMenu) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
self.navigationController.navigationBarHidden = YES;
}
- (void)goToRESideMenu {
UIViewController *redViewController = [[UIViewController alloc] init];
redViewController.view.backgroundColor = [UIColor redColor];
UIViewController *greenViewController = [[UIViewController alloc] init];
greenViewController.view.backgroundColor = [UIColor greenColor];
UIViewController *blueViewController = [[UIViewController alloc] init];
blueViewController.view.backgroundColor = [UIColor blueColor];
RESideMenu *sideMenu = [[RESideMenu alloc] initWithContentViewController:redViewController
leftMenuViewController:greenViewController
rightMenuViewController:blueViewController];
[self.navigationController pushViewController:sideMenu animated:YES];
}
@end
结果如下: