无需返回按钮即可推送到 ViewController [英] Push to ViewController without back button

查看:18
本文介绍了无需返回按钮即可推送到 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];

推荐答案

在登录后实现的Screen中,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天全站免登陆