[英]Strange behaviour when hiding Navigation Bar Back Button
I've created my Storyboard with a LoginViewController which is set as the RootViewController. 我用设置为RootViewController的LoginViewController创建了Storyboard。 If the user is already logged then I just segue to the HomeViewController.
如果用户已经登录,那么我只能选择HomeViewController。
The problem is on the HomeViewController. 问题出在HomeViewController上。 I don't want the user to navigate back to the LoginViewController so I'm trying to hide the back button in the HomeViewController using:
我不希望用户导航回到LoginViewController,所以我试图使用以下方法在HomeViewController中隐藏后退按钮:
public override void ViewWillAppear(bool animated)
{
NavigationItem.SetHidesBackButton(true, false);
}
Doing this hides the button on the HomeViewController as expected, however when I navigate to any other VC's the Back button is still hidden but tappable because I can tap where the button would be and it would navigate back to the HomeVC. 这样做会按预期隐藏HomeViewController上的按钮,但是,当我导航到任何其他VC时,“后退”按钮仍是隐藏的但可以点击,因为我可以点击按钮的位置,然后它将导航回到HomeVC。 If I then navigate again to the same VC as before, the Back button is visible.
如果我然后再次导航到与以前相同的VC,则将显示“后退”按钮。 So basically it's only hidden on the first load.
因此,基本上,它仅在第一次加载时才隐藏。
Any ideas? 有任何想法吗?
Seems problem with rootViewController
which you assign and also with navigationController
. 您分配的
rootViewController
以及navigationController
似乎出现问题。 To avoid this behaviour you should Navigate and assign rootViewController
from AppDelegate, also, improve your back button hiding code. 为了避免这种行为,您应该从AppDelegate导航并分配
rootViewController
,同时还要改进后退按钮的隐藏代码。
For more help please paste code, Thank You! 如需更多帮助,请粘贴代码,谢谢!
AppDelegate.swift AppDelegate.swift
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
var rootView: MyRootViewController = MyRootViewController()
if let window = self.window{
window.rootViewController = rootView
}
return true
}
ViewDidLoad ViewDidLoad
navigationItem.hidesBackButton = true
Don't try to hide the button. 不要试图隐藏按钮。 Use NavigationController as root.
使用NavigationController作为root。 Push login then home and remove login from navigation stack.
按登录然后返回主页,然后从导航堆栈中删除登录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.