前提・実現したいこと
Swift初心者です。クイズアプリを作ろうとしています。Segueで値を送って値の違いで表示する文字を変えようと思っています。
発生している問題・エラーメッセージ
エラーは出ていません。
該当のソースコード
Swift
1 2import UIKit 3 4class ViewController: UIViewController { 5 6 let a = "problem1" 7 let b = "problem2" 8 9 10 11 override func viewDidLoad() { 12 super.viewDidLoad() 13 // Do any additional setup after loading the view, typically from a nib. 14 } 15 16 @IBAction func returnToTop(segue:UIStoryboardSegue){} 17 18 override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 19 20 if segue.identifier == "sayFirst"{ 21 let secondVc = segue.destination as! SecondViewController 22 secondVc.a = self.a 23 }else if segue.identifier == "saySecond"{ 24 let secondVc = segue.destination as! SecondViewController 25 secondVc.b = self.b 26 27 } 28 29 } 30 31}
該当のソースコード
Swift
1import UIKit 2 3class SecondViewController: UIViewController { 4 5 var a = "" 6 var b = "" 7 8 @IBOutlet weak var Button1: UIButton! 9 @IBOutlet weak var Button2: UIButton! 10 @IBOutlet weak var Button3: UIButton! 11 @IBOutlet weak var Button4: UIButton! 12 @IBOutlet weak var aLabel: UILabel! 13 @IBOutlet weak var numberLabel: UILabel! 14 15 override func viewDidLoad() { 16 super.viewDidLoad() 17 RandomQuestion() 18 } 19 20 21 22 func RandomQuestion() { 23 if case _ = "" { 24 numberLabel.text = "1" 25 aLabel.text = "日本から見て西にあり、世界一人口が多い国は?" 26 Button1.setTitle("韓国", for: UIControl.State.normal) 27 Button2.setTitle("ロシア", for: UIControl.State.normal) 28 Button3.setTitle("インド", for: UIControl.State.normal) 29 Button4.setTitle("アメリカ", for: UIControl.State.normal) 30 31 }else if case _ = ""{ 32 numberLabel.text = "2" 33 aLabel.text = "日本から見て、地球の裏側の国はどこ?" 34 Button1.setTitle("アメリカ", for: UIControl.State.normal) 35 Button2.setTitle("ロシア", for: UIControl.State.normal) 36 Button3.setTitle("イギリス", for: UIControl.State.normal) 37 Button4.setTitle("ブラジル", for: UIControl.State.normal) 38 }else{} 39 40 // Do any additional setup after loading the view. 41 }
試したこと
色々とコードを変えてみました。
補足情報(FW/ツールのバージョンなど)
Xocde: 10.1
Swift 4.2.1
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。