推送到没有后退按钮的ViewController [英] Push to ViewController without back button

查看:87
本文介绍了推送到没有后退按钮的ViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am developing an iOS app which contains login/authentication functionality - basically first time a user logins, in they need to enter relevant login details - then they are passed to main app screens - subsequent visits to the app they will be automatically authenticated.

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

All above works fine - the issue I have is with the Navigation bar - it appears in the main screen in the main part of the app with a back button - I don't want this to be displayed as they should not be able to return to the login screen once authenticated. I guess it's using the root navigation controller which explains the logic, but is there a way to ignore the navigation controller of the login section so the back button is not displayed in the main app.

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

Below is a screenshot of the structure to help my explanation - left hand group of screens are the login process right hand is the main app structure.

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

The code used to switch screens is as follows -

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


推荐答案

在登录后实现的屏幕中,ViewDidLoad方法添加该行以隐藏条形按钮。

In the Screen which implements after login, the ViewDidLoad method add the line to hide back bar button.

self.navigationItem.hidesBackButton = YES;

此外,您可以添加'退出'选项

Additionally you can add an 'Logout' option as

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

这篇关于推送到没有后退按钮的ViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆