Pri*_*til 2 sidebar objective-c ios appdelegate side-menu
在阅读此问题之前,请参阅此视频,以便了解应用中的问题/问题.
我想做的是,
案例1:如果用户未登录应用程序,则打开应用程序登录视图后将打开,在提供用户名和密码后,它将导航到主页.
案例2:如果用户已经登录,那么在启动应用程序后它将成为主页.
我写了代码来存档这个,
在登录页面中,登录按钮的代码
- (IBAction)loginButton:(id)sender {
[self->userdefaults setBool:YES forKey:@"loginSuccess"];
[userdefaults synchronize];
HomeViewController *home=[self.storyboard instantiateViewControllerWithIdentifier:@"homeId"];
[self.navigationController pushViewController:home animated:YES];
}
Run Code Online (Sandbox Code Playgroud)
我正在存储一个值NSUserDefaults,在重新启动或打开应用程序后,在AppDelegate课程中我正在检查NSUserDefaults具有该值的条件,如果是,那么它将显示直接主页,如果没有则它将登录页面.
检查下面的代码,这是在AppDelegate课堂上写的,
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
userdefaults=[NSUserDefaults standardUserDefaults];
mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"loginSuccess"]) {
NSLog(@"Login Done!!!");
HomeViewController *homeVC=[mainStoryboard instantiateViewControllerWithIdentifier:@"homeId"];
SampleNavigationController *navigation = [[SampleNavigationController alloc] initWithRootViewController:homeVC];
// SWRevealViewController * vc= [[SWRevealViewController alloc]init];
// ExpandableTableViewController *sidemenu = (ExpandableTableViewController*)[mainStoryboard instantiateViewControllerWithIdentifier:@"sideMenu"];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = navigation;
[self.window makeKeyAndVisible];
}else
{
LoginViewController *loginVC=[mainStoryboard instantiateViewControllerWithIdentifier:@"LoginId"];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = loginVC;
[self.window makeKeyAndVisible];
}
return YES;
}
Run Code Online (Sandbox Code Playgroud)
在主页中,单击左侧导航按钮后,侧面菜单视图未打开/显示.
AppDelegate课堂上缺少什么代码?
侧面菜单视图未打开/显示,因为您没有初始化SWRevealViewController而rootViewController不是aSWRevealViewController
工作代码.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
userdefaults=[NSUserDefaults standardUserDefaults];
mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"loginSuccess"]) {
NSLog(@"Login Done!!!");
HomeViewController *homeVC=[mainStoryboard instantiateViewControllerWithIdentifier:@"homeId"];
SampleNavigationController *navigation = [[SampleNavigationController alloc] initWithRootViewController:homeVC];
ExpandableTableViewController *sidemenu = (ExpandableTableViewController*)[mainStoryboard instantiateViewControllerWithIdentifier:@"sideMenu"];
// Initialize SWRevealViewController and set it as |rootViewController|
SWRevealViewController * vc= [[SWRevealViewController alloc]initWithRearViewController:sidemenu frontViewController:navigation];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = vc;
[self.window makeKeyAndVisible];
}else
{
LoginViewController *loginVC=[mainStoryboard instantiateViewControllerWithIdentifier:@"LoginId"];
UINavigationController* navLogin = [[UINavigationController alloc] initWithRootViewController:loginVC];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Using UINavigationController here because you use
// pushViewController:animated: method in loginButton:
self.window.rootViewController = navLogin;
[self.window makeKeyAndVisible];
}
return YES;
}
Run Code Online (Sandbox Code Playgroud)
您需要loginButton:稍微更改方法以使其在第一时间起作用.
- (IBAction)loginButton:(id)sender {
[self->userdefaults setBool:YES forKey:@"loginSuccess"];
[userdefaults synchronize];
HomeViewController *home=[self.storyboard instantiateViewControllerWithIdentifier:@"homeId"];
SampleNavigationController *navigation = [[SampleNavigationController alloc] initWithRootViewController:home];
ExpandableTableViewController *sidemenu = (ExpandableTableViewController*)[self.storyboard instantiateViewControllerWithIdentifier:@"sideMenu"];
SWRevealViewController * vc= [[SWRevealViewController alloc]initWithRearViewController:sidemenu frontViewController:navigation];
[self presentViewController:vc animated:YES completion:nil];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
68 次 |
| 最近记录: |