【问题标题】:navigation controller back button is not hidden导航控制器后退按钮未隐藏
【发布时间】:2016-06-16 05:21:11
【问题描述】:

在我的应用程序中,我正在使用滑块,所以我正在使用这个库。 https://github.com/dekatotoro/SlideMenuControllerSwift 但是在使用它时,我对导航栏的使用感到困惑。 在我的 appdelegate 中我写下了这段代码

window = UIWindow(frame: UIScreen.mainScreen().bounds)
storyboard = UIStoryboard(name: "Main", bundle: nil)
let controller123 : MainViewController = (self.storyboard!.instantiateViewControllerWithIdentifier("MainViewController") as? MainViewController)!
let controllerright : drawerViewController = self.storyboard!.instantiateViewControllerWithIdentifier("drawerViewController") as! drawerViewController
let controllerleft : RightViewController = self.storyboard!.instantiateViewControllerWithIdentifier("RightViewController") as! RightViewController
let controller = SlideMenuController (mainViewController: controller123, leftMenuViewController: controllerleft, rightMenuViewController: controllerright)

navigation = UINavigationController(rootViewController: controller)
window?.rootViewController = navigation
window?.makeKeyAndVisible()

在我的主视图控制器中,我通过这段代码添加了 drwer

slideMenuController()?.addRightBarButtonWithImage(UIImage(named: "ic_menu_black_24dp")!)

因为我想要右侧的抽屉

当我从抽屉中选择一项时,我会编写此代码

let controller123 : RightViewController = (self.storyboard!.instantiateViewControllerWithIdentifier("RightViewController") as? RightViewController)!
let controllerright : drawerViewController = self.storyboard!.instantiateViewControllerWithIdentifier("drawerViewController") as! drawerViewController
let controllerleft : RightViewController = self.storyboard!.instantiateViewControllerWithIdentifier("RightViewController") as! RightViewController
let controller = SlideMenuController (mainViewController: controller123, leftMenuViewController: controllerleft, rightMenuViewController: controllerright)

navigationController?.pushViewController(controller, animated: false)

但现在的问题是我无法设置导航栏标题,甚至无法隐藏后退按钮,我该如何解决?

【问题讨论】:

  • 您是否使用以下方法签入演示代码:self.navigationItem.setHidesBackButton(true, animated:true);

标签: ios swift slider uinavigationbar


【解决方案1】:

试试这样的。在drawerViewControllerviewDidLoad() 方法中添加这一行

self.navigationItem.hidesBackButton = true
self.navigationItem.title = "Your Title"
//If you want to create a custom title View then try this 
self.navigationItem.titleView = yourview

希望这会对你有所帮助。

【讨论】:

    【解决方案2】:

    在当前视图控制器中尝试此代码“覆盖 func viewWillAppear(animated: Bool)”:

     navigationItem.hidesBackButton = true;
     navigationItem.title = "Hello";
    

    希望此代码对您有所帮助。

    【讨论】:

      【解决方案3】:

      在从 Drawer 导航的每个 ViewController 中的 viewDidLoad 中试试这个

       self.navigationItem.hidesBackButton = true
       self.navigationItem.title = "Title"
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-07-03
        • 2012-01-01
        • 2015-03-24
        • 2012-04-21
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多