推送到没有后退按钮的ViewController

Dan*_*cer 11 objective-c uinavigationcontroller ios

我正在开发一个包含登录/身份验证功能的iOS应用程序 - 基本上是用户首次登录,他们需要输入相关的登录详细信息 - 然后将它们传递到主应用程序屏幕 - 随后访问应用程序,他们将自动进行身份验证.

以上所有工作正常 - 我的问题是导航栏 - 它出现在应用程序主要部分的主屏幕中,带有后退按钮 - 我不希望这个显示,因为他们不应该返回验证后进入登录屏幕.我猜它是使用根导航控制器解释逻辑,但是有一种方法可以忽略登录部分的导航控制器,因此后退按钮不会显示在主应用程序中.

下面是帮助我解释的结构截图 - 左手组屏幕是登录过程右手是主要的app结构.

在此输入图像描述

用于切换屏幕的代码如下 -

SWRevealViewController *swRevealController = (SWRevealViewController *)navVC;
swRevealController.managedObjectContext = self.managedObjectContext;
[self.navigationController pushViewController:controller animated:YES];
Run Code Online (Sandbox Code Playgroud)

Cy-*_*4AH 23

不要推视图控制器.创建新的层次结构:

Objective-C的

[self.navigationController setViewControllers:@[controller] animated:YES];
Run Code Online (Sandbox Code Playgroud)

迅速

navigationController.setViewControllers([controller], animated:true)
Run Code Online (Sandbox Code Playgroud)


use*_*152 17

在登录后实现的Screen中,ViewDidLoad方法添加行以隐藏后退栏按钮.

self.navigationItem.hidesBackButton = YES;
Run Code Online (Sandbox Code Playgroud)

此外,您可以添加"注销"选项

UIBarButtonItem *backBarButton = [[UIBarButtonItem alloc] initWithTitle:@"Logout" style:UIBarButtonItemStyleBordered
                                                                 target:self
                                                                 action:@selector(LogoutClick)];
self.navigationItem.leftBarButtonItem = backBarButton;

-(void)LogoutClick {
    [self showLogoutAlert];
}

-(void)showLogoutAlert {

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@""
                                                message:@"Do you want to Logout ?"
                                                       delegate:self
                                              cancelButtonTitle:@"Cancel"
                                              otherButtonTitles:@"Logout", nil];
    [alert show];
}


- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {

    if (buttonIndex == 1) {
        [self.navigationController popToRootViewControllerAnimated:YES];
    }
}
Run Code Online (Sandbox Code Playgroud)