HomeViewControllerからMessageKitによるチャット機能のあるViewControllerへの画面遷移を行おうとしています。
ViewControllerの画面内にNavigationBarがないためコードを書いて作成しました。
HomeViewContollerのボタンをタップすることでViewContollerへの遷移は可能になり、作成したNavigationBarのボタンをタップすることで元の画面にも戻るようになりました。
しかし、2回目以降の遷移後自分で作成したNavigationBarとは別のNavigationBarとテキスト入力スペースができてしまいます。
イメージとしては2回目の遷移後にできるNavigationBarの動きが理想なのですが、1度目の遷移から表示する方法はないでしょうか。
ViewController
1 2 3 4 override func viewDidLoad() { 5 super.viewDidLoad() 6 7 8 self.setNavigationBar() 9 10 } 11 12 13 // ナビゲーションバーをセット 14 func setNavigationBar() { 15 let screenSize: CGRect = UIScreen.main.bounds 16 let navBar = UINavigationBar(frame: CGRect(x: 0, y: 40, width: screenSize.width, height: 44)) 17 let navItem = UINavigationItem(title: "チャット") 18 let replyItem = UIBarButtonItem(title: "戻る", style: .plain, target: nil, action: #selector(onClick(_:))) 19 navItem.leftBarButtonItem = replyItem 20 navBar.setItems([navItem], animated: false) 21 self.view.addSubview(navBar) 22 } 23 24 // ナビゲーションバーのボタンをタップしたときのアクション 25 @objc func onClick(_ sender: UIBarButtonItem) { 26 print("ボタンタップ") 27 let storyboard = UIStoryboard(name: "Main", bundle: nil) 28 let nextView = storyboard.instantiateViewController(withIdentifier: "home") 29 let navi = UINavigationController(rootViewController: nextView) 30 present(navi, animated: true, completion: nil) 31 } 32 33}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/06/06 00:24