[英]iOS MMDrawerController objective-c login view controller
我開始研究iOS,我嘗試使用MMDrawerController進行左側導航,我的AppDelegate didFinishLaunchingWithOptions代碼為:-( BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *leftView = [mainStoryboard instantiateViewControllerWithIdentifier:@"LeftViewController"];
UINavigationController *leftNav = [[UINavigationController alloc]initWithRootViewController:leftView];
UIViewController *centerView = [mainStoryboard instantiateViewControllerWithIdentifier:@"CenterViewController"];
UINavigationController *centerNav = [[UINavigationController alloc]initWithRootViewController:centerView ];
self.drawerController = [[MMDrawerController alloc] initWithCenterViewController:centerNav leftDrawerViewController:leftNav];
self.drawerController.openDrawerGestureModeMask = MMOpenDrawerGestureModePanningCenterView;
self.drawerController.closeDrawerGestureModeMask = MMCloseDrawerGestureModePanningCenterView;
self.window.rootViewController = self.drawerController;
[self.window makeKeyAndVisible];
// Override point for customization after application launch.
return YES;
}
這樣就可以了,但是我的應用程序上有LoginViewController
,如果用戶在NSUserDefaults
上沒有保存的令牌,則必須顯示LogionViewController。 當然,側面菜單必須在LoginViewController
上隱藏。
我試圖切換到CenterViewController
內部的LoginViewController:
- (void)viewDidLoad {
[super viewDidLoad];
LoginViewController * vc = [[LoginViewController alloc] init];
AppDelegate *app = [[UIApplication sharedApplication] delegate];
[app.drawerController setCenterViewController:vc withCloseAnimation:YES completion:nil];
}
但是我只有黑屏。 我做錯了什么? 謝謝
您正在執行的操作有點怪異,因為您正在當前( CenterViewController
類型)中設置新的centerViewController
(類型LoginViewController
),並且一旦完成,將取消分配后者,因為沒有更多引用了。 這可能會導致黑屏。
一種解決方案是將LoginViewController
放在MMDrawerController
之外,並始終在開始時顯示它。 如果沒有令牌,則快速(不帶動畫)顯示MMDrawerController
,甚至看不到LoginViewController
。 如果用戶注銷,這種方式還可以讓您輕松地退出登錄屏幕。
另一個選擇是使用presentViewController:animated:completion:
以模態方式(或您確實喜歡)從CenterViewController
呈現LoginViewController
,然后在他們登錄時將其關閉。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.