Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/105.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS MMDroperController目标-c登录视图控制器_Ios_Objective C_Mmdrawercontroller - Fatal编程技术网

iOS MMDroperController目标-c登录视图控制器

iOS MMDroperController目标-c登录视图控制器,ios,objective-c,mmdrawercontroller,Ios,Objective C,Mmdrawercontroller,我开始学习iOS,并尝试使用 我的AppDelegate didFinishLaunchingWithOptions代码为: -(BOOL)应用程序:(UIApplication*)应用程序 didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]

我开始学习iOS,并尝试使用 我的AppDelegate didFinishLaunchingWithOptions代码为: -(BOOL)应用程序:(UIApplication*)应用程序

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
,然后在他们登录时将其关闭。

谢谢,但最好的方法是什么?此外,我还放弃了PasswordViewController和RegistrationViewController,因此有3个非MMDrawerViewController。