Ios 不带“后退”按钮,按到ViewController

Ios 不带“后退”按钮,按到ViewController,ios,objective-c,uinavigationcontroller,Ios,Objective C,Uinavigationcontroller,我正在开发一个iOS应用程序,它包含登录/身份验证功能-基本上是用户第一次登录,因为他们需要输入相关的登录详细信息-然后将其传递到主应用程序屏幕-随后访问应用程序时,他们将自动进行身份验证 以上所有工作正常-我的问题是导航栏-它出现在应用程序主要部分的主屏幕上,带有后退按钮-我不希望显示此内容,因为一旦验证,他们将无法返回登录屏幕。我猜它使用了根导航控制器来解释逻辑,但是有没有办法忽略登录部分的导航控制器,这样主应用程序中就不会显示后退按钮 下面是帮助我解释的结构截图-左侧屏幕组是登录过程,右侧

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

以上所有工作正常-我的问题是导航栏-它出现在应用程序主要部分的主屏幕上,带有后退按钮-我不希望显示此内容,因为一旦验证,他们将无法返回登录屏幕。我猜它使用了根导航控制器来解释逻辑,但是有没有办法忽略登录部分的导航控制器,这样主应用程序中就不会显示后退按钮

下面是帮助我解释的结构截图-左侧屏幕组是登录过程,右侧是主应用程序结构

用于切换屏幕的代码如下所示:

SWRevealViewController *swRevealController = (SWRevealViewController *)navVC;
swRevealController.managedObjectContext = self.managedObjectContext;
[self.navigationController pushViewController:controller animated:YES];

在登录后实现的屏幕中,ViewDidLoad方法添加行隐藏返回栏按钮

self.navigationItem.hidesBackButton = YES;
此外,您还可以添加“注销”选项,如下所示:

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];
    }
}

不要推视图控制器。使用以下内容创建新的层次结构:

目标-C

[self.navigationController setViewControllers:@[controller] animated:YES];
迅捷的


很简单。。只需导航到rootviewcontroller

 SWRevealViewController *swRevealController = (SWRevealViewController *)navVC;
 swRevealController.managedObjectContext = self.managedObjectContext;
 //-- I think above lines not needed as per your question
 [self.navigationController popToRootViewControllerAnimated:YES];

在viewDidLoad方法中编写

self.navigationItem.hidesBackButton = YES;

在登录屏幕上使用模态视图控制器,使其不属于导航根目录中的导航控制器层次结构的一部分。视图中可能加载了以下示例代码:

  - (void) viewDidLoad {
......
  LoginVC *loginViewController = [LoginVC alloc] init];
  loginViewController.parent = self;  
  [self presentViewController: loginViewController animated:YES completion:NULL];
  return;
      }
您可以从根目录中取消模式视图,也可以不取消模式视图-如果取消,您需要能够从loginViewController调用取消例程,但还有其他方法,您可以将取消放入模式视图(loginViewController)中

  • (void)登录退出:(BOOL)成功{ [self-dismissViewControllerAnimated:是完成:空]

    如果!(成功){
    ..发送消息(查看并询问他或她是否想再试一次) } 否则{ } 返回;}


在使用viewDidLoad中的下一行按下SWRevealViewController之前,需要隐藏ViewController中的导航栏

目标C

self.navigationController.navigationBarHidden = true;
迅捷的


它不会在按下控制器的下一个视图中显示后退按钮,这将隐藏第一个视图的后退按钮

ClassA* controller = [storyboard instantiateViewControllerWithIdentifier:@"ClassAIdentifier"];

if (controller != nil) {
        [self.navigationController pushViewController:controller animated:YES];
        [controller.navigationItem setHidesBackButton:YES animated:NO];    
    }

推送后必须隐藏navigationItem,否则它将为零。

不要在<代码>情节提要或<代码>AppDelegate中实现navigationController,它应该与Def类似。“重置”当前viewstack的最佳解决方案
self.navigationController?.navigationBarHidden = true;
ClassA* controller = [storyboard instantiateViewControllerWithIdentifier:@"ClassAIdentifier"];

if (controller != nil) {
        [self.navigationController pushViewController:controller animated:YES];
        [controller.navigationItem setHidesBackButton:YES animated:NO];    
    }