A・B・Cから構成される画面があります。
A画面のButtonをタップすると、B画面へと遷移します。B画面のButtonをタップすると、A画面に戻りつつInt型の数字をA画面に渡します。ここでif文を使用し、B画面から渡された数字と一致するとき、A画面のButtonをタップすることで、C画面に遷移できるようにしたいです。
【問題点】
B画面からA画面に戻った際、コンソールより数字が渡されていることを確認できます。よってif文条件を満たしているように考えられるにも拘らず、C画面へ遷移せずB画面へ遷移してしまいます。
以下、コードです。ご教授をお願いいたします。
Swift
1AppDelegate 2 3var window: UIWindow? 4var Inta:Int? 5
Swift
1GamenBViewController 2//値渡し元 3 4override func viewDidLoad() { 5 super.viewDidLoad() 6 7 let nextVC = self.storyboard?.instantiateViewController(withIdentifier:"gamenA") 8 present(nextVC!,animated:false,completion: nil) 9 } 10 11 @IBAction func hoge(_ sender: Any) { 12 let appDelegate = UIApplication.shared.delegate as! AppDelegate 13 appDelegate.Inta = 1 14 }
Swift
1GamenAViewController 2//値渡し先 3 4var atai:Int! 5 6override func viewDidLoad() { 7 super.viewDidLoad() 8 9 let appDelegate = UIApplication.shared.delegate as! AppDelegate 10 atai = appDelegate.Inta 11 print(atai) 12 } 13 14@IBAction func Button(_ sender: Any) { 15 16 if atai == nil { 17 18 let storyboard: UIStoryboard = self.storyboard! 19 let nextView = storyboard.instantiateViewController(withIdentifier: "GamenB") as! BViewController 20 nextView.modalTransitionStyle = UIModalTransitionStyle.crossDissolve; 21 self.present(nextView, animated: true, completion: nil) 22 } else if atai == 1 { 23 24 let storyboardS: UIStoryboard = self.storyboard! 25 let nextViewS = storyboardS.instantiateViewController(withIdentifier: "GamenC") as! CViewController 26 nextViewS.modalTransitionStyle = UIModalTransitionStyle.crossDissolve; 27 self.present(nextViewS, animated: true, completion: nil) 28 29 } 30 }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/01/12 08:27
2018/01/12 08:35
2018/01/15 05:46