Ios 故事板上的侧栏导航菜单
我已经学习了关于如何创建登录/注册屏幕的TreeHouse教程,以及关于添加侧栏导航菜单的AppCoda教程: 我将登录/注册栏连接到主viewcontroller,主viewcontroller连接到侧栏viewcontroller。这导致了一个有趣的bug,我可以在不登录的情况下进入主屏幕 有谁能建议一个故事板布局,让我只在登录时才可以滑动侧边栏Ios 故事板上的侧栏导航菜单,ios,storyboard,sidebar,Ios,Storyboard,Sidebar,我已经学习了关于如何创建登录/注册屏幕的TreeHouse教程,以及关于添加侧栏导航菜单的AppCoda教程: 我将登录/注册栏连接到主viewcontroller,主viewcontroller连接到侧栏viewcontroller。这导致了一个有趣的bug,我可以在不登录的情况下进入主屏幕 有谁能建议一个故事板布局,让我只在登录时才可以滑动侧边栏 我通常处理这个问题的方式是使用另一个viewController来处理登录,这不是主应用程序导航的一部分 然后,登录控制器可以执行登录所需的任何
我通常处理这个问题的方式是使用另一个viewController来处理登录,这不是主应用程序导航的一部分 然后,登录控制器可以执行登录所需的任何操作,并在用户通过身份验证后执行以下操作:
-(void) loginDidComplete {
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:kLoginKey];
AppDelegate *appDelegateTemp = [[UIApplication sharedApplication]delegate];
appDelegateTemp.window.rootViewController = [[UIStoryboard storyboardWithName:@"MainStoryboard"
bundle:[NSBundle mainBundle]]
instantiateInitialViewController];
[[NSNotificationCenter defaultCenter] postNotificationName:@"UserDidLogin" object:nil userInfo:nil];
}
在app delegate的应用程序didFinishLaunchingWithOptions中,我们可以通过执行以下操作来检查用户是否登录:
if ([User userAuthenticated] ) //if user is auth correctly, then we go to the main view
{
self.window.rootViewController = [[UIStoryboard storyboardWithName:@"MainStoryboard"
bundle:[NSBundle mainBundle]]
instantiateInitialViewController];
}
else //otherwise we show the login controller
{
self.window.rootViewController = [[UIStoryboard storyboardWithName:@"MainStoryboard"
bundle:[NSBundle mainBundle]]
instantiateViewControllerWithIdentifier:@"LoginViewController"];
}
添加了一个屏幕截图以演示故事板中的2个ViewController
我通常处理这个问题的方式是使用另一个viewController来处理登录,这不是主应用程序导航的一部分 然后,登录控制器可以执行登录所需的任何操作,并在用户通过身份验证后执行以下操作:
-(void) loginDidComplete {
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:kLoginKey];
AppDelegate *appDelegateTemp = [[UIApplication sharedApplication]delegate];
appDelegateTemp.window.rootViewController = [[UIStoryboard storyboardWithName:@"MainStoryboard"
bundle:[NSBundle mainBundle]]
instantiateInitialViewController];
[[NSNotificationCenter defaultCenter] postNotificationName:@"UserDidLogin" object:nil userInfo:nil];
}
在app delegate的应用程序didFinishLaunchingWithOptions中,我们可以通过执行以下操作来检查用户是否登录:
if ([User userAuthenticated] ) //if user is auth correctly, then we go to the main view
{
self.window.rootViewController = [[UIStoryboard storyboardWithName:@"MainStoryboard"
bundle:[NSBundle mainBundle]]
instantiateInitialViewController];
}
else //otherwise we show the login controller
{
self.window.rootViewController = [[UIStoryboard storyboardWithName:@"MainStoryboard"
bundle:[NSBundle mainBundle]]
instantiateViewControllerWithIdentifier:@"LoginViewController"];
}
添加了一个屏幕截图以演示故事板中的2个ViewController
在您的LoginController(或什么名称)中,在viewDidLoad
中添加此行:
self.navigationController.interactiveEPGESTurerecognizer.enabled=否代码>
它将停止弹出的默认平移手势。试试看。在您的LoginController(或什么名称)中,在viewDidLoad
中添加这一行:
self.navigationController.interactiveEPGESTurerecognizer.enabled=否代码>
它将停止弹出的默认平移手势。试试。我理解正确,您的RootViewController是MasterViewController,当用户打开您的应用程序时,如果他没有登录,他将重定向到登录页面(通过推送(?)导航)?是的,正确!我确实将其设置为root我理解正确,您的RootViewController是MasterViewController,当用户打开您的应用程序时,如果他没有登录,他将重定向到登录页面(通过推送(?)导航)?是的,正确!对不起,我不太清楚如何落实你的建议。我刚刚开始并开始学习故事板,那么您是否可以展示一个关于故事板布局的图像示例?我使用Parse作为登录身份验证程序,当我第一次启动MasterViewController时,它会在那里检查登录身份验证。如果未登录,则推到登录屏幕。我添加了一个屏幕截图,因此基本上我的“MasterViewController”将执行应用程序应该执行的操作。登录viewcontroller将负责登录。然后,您只需根据需要更改这两件事。或者,我想另一种方法是,当用户未登录时,从MasterViewController以模式显示登录屏幕。然后,在用户可以看到它下面的视图之前,它必须被取消。可能更容易。对不起,我真的不知道如何实施你的建议。我刚刚开始并开始学习故事板,那么您是否可以展示一个关于故事板布局的图像示例?我使用Parse作为登录身份验证程序,当我第一次启动MasterViewController时,它会在那里检查登录身份验证。如果未登录,则推到登录屏幕。我添加了一个屏幕截图,因此基本上我的“MasterViewController”将执行应用程序应该执行的操作。登录viewcontroller将负责登录。然后,您只需根据需要更改这两件事。或者,我想另一种方法是,当用户未登录时,从MasterViewController以模式显示登录屏幕。然后,在用户可以看到它下面的视图之前,它必须被取消。可能更容易。