アプリ開発初心者です。
現在、追加した値を元にカウントダウンを行うアプリを作成しているのですが、行き詰まってしまいました。
下記のコード内の追加画面への遷移buttonをタップすると
落ちてしまいます。
コメントアウトしている箇所は、
元々はそのままにしていても動作していたのですが、
スタックオーバーフローが起こってしまったのか、
動作しなくなったので、コメントアウトしています。(関係あるかわかりませんが、動作上おかしくなる部分も含む)
自分なりに色々と調べたりしたのですが、
解決策が見つからなかったので、質問させていただきました。
//追記
以下のコードを色々と書き換える前に
warning:could not load any Objective-C class information from the dyld shared cache. This will significantly reduce the quality of type information available.
とコンソールに表示されたので、現在の以下のコードを実行したときには表示されませんが、もしかしたら、現段階でも発生しているのかと思い、質問内容に含めさせていただきました。
Swift
1 2import UIKit 3 4class TopActivity: UIViewController { 5 6 var a: Int = 0 //保存した値を一度だけ取得 7 var c: Int = 0 8 var b: Int = 0 9 var intVal: Int! 10 var d: Int = 0 11 var timelog: Int = 0 12 var timerTime = NSUserDefaults.standardUserDefaults() 13 14 //CountDown 15 var timerCount: Int = 0 16 var timer = NSTimer() 17 18 //タイマー 19 @IBOutlet weak var timerlabel: UILabel! 20 21 func Counting(){ 22 timerCount += timelog 23 24 25 if(timerCount == 0){ 26 //timerlabel.text = "0" 27 timer.invalidate() 28 }else{ 29 30 timerCount -= 1 31 timerlabel.text = "\(timerCount / 60) min \(timerCount % 60) sec" 32 33 // 毎秒、値を保存 34 /*timerTime.setObject(timerCount, forKey: "timeKey") 35 timerTime.synchronize() 36 */ 37 if(timerCount == -1&&d == 1){ 38 39 timerlabel.text = "カウントダウン終了" 40 } 41 } 42} 43 44 45@IBAction func toptoselect(sender: UIButton) {//追加画面への遷移button 46 47 timerTime.setObject(timerCount, forKey: "timeKey") 48 timerTime.synchronize() 49 50 timerCount = 0 51 //timer.invalidate() 52} 53 54override func viewDidLoad() { 55 56 super.viewDidLoad() 57 58 /* 59 timerTime.registerDefaults(["timekey": 1])// デフォルト値 60 61 var f = 0 62 63 if(f==0){ 64 timelog = timerTime.objectForKey("timeKey") as! Int 65 f += 1 66 } 67 */ 68 69 timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: Selector("Counting"), userInfo: nil, repeats: true) 70 71} 72 73override func didReceiveMemoryWarning() { 74 75 super.didReceiveMemoryWarning() 76 77 // Dispose of any resources that can be recreated. 78} 79}
回答1件
あなたの回答
tips
プレビュー