ご覧いただき、有難うございます。
DropDownMenuのライブラリを使用しているのですが、
メニューの「Month」セルをタップすると、画面遷移と同時にナビゲーションバータのイトルも「Month」に変わるのですが、そこから「Day」セルをタップしても、画面遷移とともにナビゲーションバーのタイトルが変わりません。
また、「Month」のViewControllerにはSegueを繋いでいないので、NavigationControllerを継承していません。やや無理やりですが、NavigationControllerを生成しております。AppDelegateでNavigationControllerを生成しようとしましたが、うまくいきませんでした。
下記URLを参考にしました。
【Swift】BTNavigationDropdownMenu使ってみた【簡単にドロップダウンメニューが作れる!】
タップしたメニューに適したタイトル(「Day」なら「Day」「Month」なら「Month」)に変更するためにはどのようにコードを訂正すればよろしいでしょうか。ご教示お願いいたします。
// ViewController.swift let items = ["Daily", "Month"] var menuView: BTNavigationDropdownMenu! override func viewDidLoad() { super.viewDidLoad() var menuView = BTNavigationDropdownMenu(navigationController: self.navigationController, containerView: self.navigationController!.view, title: "Dropdown Menu", items: items as [AnyObject]) menuView = BTNavigationDropdownMenu(title: items[0], items: items as [AnyObject]) self.navigationController?.navigationBar.isTranslucent = false self.navigationController?.navigationBar.barTintColor = UIColor(red: 0.0/255.0, green:180/255.0, blue:220/255.0, alpha: 1.0) self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.white] self.navigationItem.titleView = menuView menuView.didSelectItemAtIndexHandler = {[weak self] (indexPath: Int) -> () in print("Did select item at index: \(indexPath)") if indexPath == 1 { let monthViewController = self?.storyboard?.instantiateViewController(withIdentifier: "Month") let navigationController = UINavigationController(rootViewController: monthViewController!) self?.present(navigationController, animated: false, completion:nil) } } }
// MonthViewController.swift let items = ["Daily", "Month"] var menuView: BTNavigationDropdownMenu! override func viewDidLoad() { super.viewDidLoad() var menuView = BTNavigationDropdownMenu(navigationController: self.navigationController, containerView: self.navigationController!.view, title: "Dropdown Menu", items: items as [AnyObject]) menuView = BTNavigationDropdownMenu(title: items[1], items: items as [AnyObject]) self.navigationController?.navigationBar.isTranslucent = false self.navigationController?.navigationBar.barTintColor = UIColor(red: 0.0/255.0, green:180/255.0, blue:220/255.0, alpha: 1.0) self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.white] self.navigationItem.titleView = menuView menuView.didSelectItemAtIndexHandler = {[weak self] (indexPath: Int) -> () in print("Did select item at index: \(indexPath)") if indexPath == 0 { self?.dismiss(animated: true, completion: nil) } } }