xcodeでシミュレータを使ってみると、止まってしまい、以下のようなエラーが出てしまいます。どうしたら良いでしょうか?
swift
1 2 3import UIKit 4 5class PlayViewController: UIViewController { 6 7 @IBOutlet weak var 問題ラベル: UILabel! 8 @IBOutlet var 残り時間ビュー: UIProgressView! 9 10 @IBOutlet var 解答ボタン: [UIButton]! 11 12 13 let 問題リスト=[ 14 ["「3番目」を表す英語は?","third","fifth"], 15 ["「come」の過去形は?","came","come","comed"], 16 ["「8月」を表す英語は?","Augst","November"] 17 ] 18 19 var 問題番号 = 0; 20 var 残り時間 = 10; 21 var 正解数 = 0; 22 var タイマー :Timer? 23 24 25 26 27 28 override func viewDidLoad() { 29 super.viewDidLoad() 30 31 出題() 32 33 // Do any additional setup after loading the view. 34 } 35 36 func 出題(){ 37 let 問題データ = 問題リスト[問題番号] 38 問題ラベル.text = 問題データ[0] 39 let 番号 = 番号リスト() 40 for i in 0...2{ 41 解答ボタン[i].setTitle(問題データ[番号[i]],for: .normal) 42 } 43 残り時間 = 10 44 残り時間ビュー.progress = 1.0 45 タイマー = Timer.scheduledTimer(timeInterval: 1.0,target:self,selector: #selector(タイマー関数),userInfo: nil, repeats:true) 46 } 47 48 func 番号リスト() ->[Int]{ 49 var リスト = [1,2,3] 50 for _ in 1...10{ 51 let i1 = Int(arc4random() % 3) 52 let i2 = Int(arc4random() % 3) 53 if i1 != i2{ 54 swap(&リスト[i1],&リスト[i2]) 55 } 56 } 57 return リスト 58 } 59 60 func タイマー関数(){ 61 残り時間 -= 1 62 残り時間ビュー.progress = Float(残り時間)/10 63 if 残り時間 == 0{ 64 問題番号 += 1 65 出題() 66 } 67 } 68 69 70 @IBAction func 解答チェック(_ sender: AnyObject) { 71 タイマー!.invalidate() 72 let 解答 = sender.currentTitle! 73 let 問題データ = 問題リスト[問題番号] 74 let 解答番号 = 問題データ.index(of: 解答!)! 75 let alert = UIAlertController(title: "\(問題番号+1)問目",message:"",preferredStyle: .alert) 76 if 解答番号 == 1{ 77 正解数 += 1 78 alert.message = "正解!!" 79 }else { 80 alert.message = "はずれ!!" 81 } 82 let action = UIAlertAction(title:"OK",style:UIAlertActionStyle.default,handler:{(_) ->Void in 83 self.問題番号 += 1 84 self.出題() 85 }) 86 alert.addAction(action) 87 present(alert,animated: true,completion:nil) 88 89 } 90 91 92 93 94 95 96 override func didReceiveMemoryWarning() { 97 super.didReceiveMemoryWarning() 98 // Dispose of any resources that can be recreated. 99 } 100 101 102} 103 104 /* 105 // MARK: - Navigation 106 107 // In a storyboard-based application, you will often want to do a little preparation before navigation 108 override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 109 // Get the new view controller using segue.destinationViewController. 110 // Pass the selected object to the new view controller. 111 } 112 */ 113 114 115
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/02/03 11:06