クイズアプリを作っているんですが問題がエンドレスに出てしまい、どうやったら全問といて終わるのかわかりません……
また、同じ問題が何回か出てきたりしますその直し方も教えていただきたいです。
Swift
1import UIKit 2 3class ViewController: UIViewController { 4 5 6 @IBOutlet var QuestionLabel: UILabel! 7 8 @IBOutlet var Button1: UIButton! 9 @IBOutlet var Button2: UIButton! 10 @IBOutlet var Button3: UIButton! 11 @IBOutlet var Button4: UIButton! 12 13 @IBOutlet var LabelEnd: UILabel! 14 15 @IBOutlet var Next: UIButton! 16 var CorrectAnswer = String() 17 18 19 20 override func viewDidLoad() { 21 super.viewDidLoad() 22 // Do any additional setup after loading the view, typically from a nib. 23 24 Hide() 25 26 RandomQuestions() 27 } 28 29 override func didReceiveMemoryWarning() { 30 super.didReceiveMemoryWarning() 31 // Dispose of any resources that can be recreated. 32 } 33 34 35 func RandomQuestions(){ 36 37 var RandomNumber = arc4random() % 10 38 RandomNumber += 1 39 40 switch(RandomNumber){ 41 42 43 44 case 1: 45 46 QuestionLabel.text = "" 47 Button1.setTitle("", forState: UIControlState.Normal) 48 Button2.setTitle("", forState: UIControlState.Normal) 49 Button3.setTitle("", forState: UIControlState.Normal) 50 Button4.setTitle("", forState: UIControlState.Normal) 51 CorrectAnswer = "" 52 53 54 break 55 case 2: 56 QuestionLabel.text = "" 57 Button1.setTitle("", forState: UIControlState.Normal) 58 Button2.setTitle("", forState: UIControlState.Normal) 59 Button3.setTitle("", forState: UIControlState.Normal) 60 Button4.setTitle("", forState: UIControlState.Normal) 61 CorrectAnswer = "" 62 63 64 break 65 case 3: 66 QuestionLabel.text = "" 67 Button1.setTitle("", forState: UIControlState.Normal) 68 Button2.setTitle("", forState: UIControlState.Normal) 69 Button3.setTitle("", forState: UIControlState.Normal) 70 Button4.setTitle("", forState: UIControlState.Normal) 71 CorrectAnswer = "" 72 73 74 break 75 case 4: 76 QuestionLabel.text = "" 77 Button1.setTitle("", forState: UIControlState.Normal) 78 Button2.setTitle("", forState: UIControlState.Normal) 79 Button3.setTitle("", forState: UIControlState.Normal) 80 Button4.setTitle("", forState: UIControlState.Normal) 81 CorrectAnswer = "" 82 83 84 break 85 case 5: 86 QuestionLabel.text = "" 87 Button1.setTitle("", forState: UIControlState.Normal) 88 Button2.setTitle("", forState: UIControlState.Normal) 89 Button3.setTitle("", forState: UIControlState.Normal) 90 Button4.setTitle("", forState: UIControlState.Normal) 91 CorrectAnswer = "" 92 93 94 break 95 case 6: 96 QuestionLabel.text = "" 97 Button1.setTitle("", forState: UIControlState.Normal) 98 Button2.setTitle("", forState: UIControlState.Normal) 99 Button3.setTitle("", forState: UIControlState.Normal) 100 Button4.setTitle("", forState: UIControlState.Normal) 101 CorrectAnswer = "" 102 break 103 104 105 case 7: 106 QuestionLabel.text = "" 107 Button1.setTitle("", forState: UIControlState.Normal) 108 Button2.setTitle("", forState: UIControlState.Normal) 109 Button3.setTitle("", forState: UIControlState.Normal) 110 Button4.setTitle("", forState: UIControlState.Normal) 111 CorrectAnswer = "" 112 break 113 114 115 default: 116 117 break 118 119 } 120 } 121 122 func Hide(){ 123 LabelEnd.hidden = true 124 Next.hidden = true 125 } 126 127 func UnHide(){ 128 LabelEnd.hidden = false 129 Next.hidden = false 130 } 131 132 133 134 135 136 @IBAction func Button1Action(sender: AnyObject) { 137 138 UnHide() 139 140 if (CorrectAnswer == "1"){ 141 142 LabelEnd.text = "正解だよ!" 143 } 144 else{ 145 LabelEnd.text = "ザンネーン!!" 146 } 147 148 149 } 150 151 @IBAction func Button2Action(sender: AnyObject) { 152 153 UnHide() 154 155 if (CorrectAnswer == "2"){ 156 157 LabelEnd.text = "正解だよ!" 158 } 159 else{ 160 LabelEnd.text = "ザンネーン!!" 161 } 162 } 163 164 165 @IBAction func Button3Action(sender: AnyObject) { 166 167 UnHide() 168 169 if (CorrectAnswer == "3"){ 170 171 LabelEnd.text = "正解だよ!" 172 } 173 else{ 174 LabelEnd.text = "ザンネーン!!" 175 } 176 177 } 178 179 @IBAction func Button4Action(sender: AnyObject) { 180 181 UnHide() 182 183 if (CorrectAnswer == "4"){ 184 185 LabelEnd.text = "正解だよ!" 186 } 187 else{ 188 LabelEnd.text = "ザンネーン!!" 189 } 190 } 191 192 193 194 @IBAction func Next(sender: AnyObject) { 195 196 RandomQuestions() 197 Hide() 198 199 200 } 201 202 }
長文失礼します
回答2件
あなたの回答
tips
プレビュー