###前提・実現したいこと
NavigationBar <Backボタンの連打防止
###発生している問題・エラーメッセージ
A->B->Cへ画面遷移した後
C画面にて表示されているNavigationBarの戻るボタン[< B]を連打すると
A画面まで戻ってしまいます。
NavigationBarのボタンに対して
isEnableの設定など出来るのでしょうか。
何か有効な手段を教えて頂けますでしょうか
###試したこと
lang
1import UIKit 2 3class FirstViewController: UIViewController { 4 5 override func viewDidLoad() { 6 super.viewDidLoad() 7 8 self.view.backgroundColor = UIColor.red 9 10 // ボタンを生成する. 11 let myButton = UIButton(frame: CGRect(x:0,y:0,width:100,height:100)) 12 myButton.backgroundColor = UIColor.orange 13 myButton.setTitle("ボタン", for: .normal) 14 myButton.layer.position = CGPoint(x: self.view.bounds.width/2, y:200) 15 myButton.addTarget(self, action: #selector(FirstViewController.onClickMyButton(sender:)), for: .touchUpInside) 16 17 // ボタンをViewに追加する. 18 self.view.addSubview(myButton); 19 20 // NavigationBarの表示する. 21 self.navigationController?.setNavigationBarHidden(false, animated: false) 22 self.navigationItem.title = "A" 23 } 24 25 /* 26 ボタンイベント 27 */ 28 internal func onClickMyButton(sender: UIButton){ 29 print("onClickMyButton:") 30 31 let secondViewController = SecondViewController() 32 self.navigationController?.pushViewController(secondViewController, animated: true) 33 } 34 35 override func didReceiveMemoryWarning() { 36 super.didReceiveMemoryWarning() 37 // Dispose of any resources that can be recreated. 38 } 39} 40
lang
1import UIKit 2 3class SecondViewController: UIViewController { 4 5 override func viewDidLoad() { 6 super.viewDidLoad() 7 8 self.title = "B" 9 self.view.backgroundColor = UIColor.yellow 10 11 // ボタンを生成する. 12 let myButton = UIButton(frame: CGRect(x:0,y:0,width:100,height:100)) 13 myButton.backgroundColor = UIColor.orange 14 myButton.setTitle("ボタン", for: .normal) 15 myButton.layer.position = CGPoint(x: self.view.bounds.width/2, y:200) 16 myButton.addTarget(self, action: #selector(SecondViewController.onClickMyButton(sender:)), for: .touchUpInside) 17 18 // ボタンをViewに追加する. 19 self.view.addSubview(myButton); 20 } 21 22 23 override func didReceiveMemoryWarning() { 24 super.didReceiveMemoryWarning() 25 // Dispose of any resources that can be recreated. 26 } 27 28 /* 29 ボタンイベント 30 */ 31 internal func onClickMyButton(sender: UIButton){ 32 print("onClickMyButton:") 33 34 let thirdViewController = ThirdViewController() 35 self.navigationController?.pushViewController(thirdViewController, animated: true) 36 } 37 38}
lang
1import UIKit 2 3class ThirdViewController: UIViewController { 4 5 override func viewDidLoad() { 6 super.viewDidLoad() 7 self.title = "C" 8 self.view.backgroundColor = UIColor.blue 9 } 10 11 override func didReceiveMemoryWarning() { 12 super.didReceiveMemoryWarning() 13 // Dispose of any resources that can be recreated. 14 } 15 16}
###補足情報(言語/FW/ツール等のバージョンなど)
XCode8.3.3
Swift3
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/07/30 02:00
2017/07/30 05:01