在我的应用程序中我使用滑块,所以我使用这个库。 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()
在我的mainviewcontroller中,我通过此代码添加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)
但现在问题是我无法设置导航栏标题,甚至我无法隐藏后退按钮所以我该如何解决?
答案 0 :(得分:1)
尝试这样的事情。在viewDidLoad()
drawerViewController
方法中添加此行
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
希望这会对你有所帮助。
答案 1 :(得分:0)
在当前视图控制器中尝试此代码“覆盖func viewWillAppear(animated:Bool)”:
navigationItem.hidesBackButton = true;
navigationItem.title = "Hello";
希望此代码能为您提供帮助。
答案 2 :(得分:0)
在每个从Drawer
导航的ViewController中的viewDidLoad中尝试此操作 self.navigationItem.hidesBackButton = true
self.navigationItem.title = "Title"