前提・実現したいこと
昨日(8/29)までiPhoneやシュミレーターではちゃんと結果が出ました。
しかし、今日(2020/08/30)になって急に真っ白になってしまいました。
ドットインストールで、ブラウザーサイトを作っていました。
ViewController.swiftは赤いエラーは出ていませんでした。
発生している問題・エラーメッセージ
Thread 1: Exception: "[<mystopwatchapp.ViewController 0x7fb3cf408c90> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key resetbutton2."
該当のソースコード
swiftです。
1// 2// AppDelegate.swift 3// mystopwatchapp 4// 5// Created by user on 2020/08/22. 6// Copyright © 2020 user. All rights reserved. 7// 8 9import UIKit 10 11@UIApplicationMain 12**class AppDelegate: UIResponder, UIApplicationDelegate **{ 13 14 15 16 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 17 // Override point for customization after application launch. 18 return true 19 } 20 21 // MARK: UISceneSession Lifecycle 22 23 func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { 24 // Called when a new scene session is being created. 25 // Use this method to select a configuration to create the new scene with. 26 return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) 27 } 28 29 func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) { 30 // Called when the user discards a scene session. 31 // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. 32 // Use this method to release any resources that were specific to the discarded scenes, as they will not return. 33 } 34 35 36} 37
試したこと
同じような質問がありましたが、うまくいきませんでした。
補足情報(FW/ツールのバージョンなど)
ViewControllerの中身です。
// // ViewController.swift // mystopwatchapp // // Created by user on 2020/08/22. // Copyright © 2020 user. All rights reserved. // import UIKit class ViewController: UIViewController { @IBOutlet weak var timerLavel: UILabel! @IBOutlet weak var startButton: UIButton! @IBOutlet weak var stopButton: UIButton! @IBOutlet weak var resetButton: UIButton! @IBOutlet weak var timerLavel2: UILabel! @IBOutlet weak var startButton2: UIButton! @IBOutlet weak var stopButton2: UIButton! @IBOutlet weak var resetButton2: UIButton! var startTime: TimeInterval? = nil var timer = Timer() var elapsedTime: Double = 0.0 override func viewDidLoad() { super.viewDidLoad() // start: true, stop: false, reset: false setButtonEanble(start: true, stop: false, reset: false) // Do any additional setup after loading the view. //startButton.layer.borderWidth = 2 //startButton.layer.borderColor = UIColor.orange.cgColor // myLabel.layer.borderWidth = 5 //startButton.layer.cornerRadius = 50 startButton.layer.masksToBounds = true startButton.layer.cornerRadius = startButton.bounds.width / 2 stopButton.layer.masksToBounds = true stopButton.layer.cornerRadius = startButton.bounds.width / 2 //resetButton.layer.masksToBounds = true //resetButton.layer.cornerRadius = startButton.bounds.width / 2 } func setButtonEanble(start: Bool, stop: Bool, reset:Bool) { self.startButton.isEnabled = start self.stopButton.isEnabled = stop self.resetButton.isEnabled = reset } @objc func update() { // 2001/1/1 00:00:00: // print(Date.timeIntervalSinceReferenceDate) if let startTime = self.startTime { let t: Double = Date.timeIntervalSinceReferenceDate - startTime + self.elapsedTime //print(t) let min = Int(t / 60) let sec = Int(t) % 60 let msec = Int(t * 100) % 100 let mmsec = Int(t * 100 * 100 ) % 100 let mmmsec = Int(t * 100 * 100 * 100) % 100 let mmmmsec = Int(t * 100 * 100 * 100 * 100) % 100 let mmmmmsec = Int(t * 100 * 100 * 100 * 100 * 100) % 100 self.timerLavel.text = String(format: "%02d:%02d:%02d:%02d:%02d:%02d:%02d", min, sec, msec, mmsec, mmmsec, mmmmsec, mmmmmsec) } } @IBAction func startTimer(_ sender: Any) { // start: true, stop: false, reset: false setButtonEanble(start: false, stop: true, reset: false) self.startTime = Date.timeIntervalSinceReferenceDate self.timer = Timer.scheduledTimer( timeInterval: 0.01, target: self, selector: #selector(self.update), userInfo: nil, repeats: true) } @IBAction func stopTimer(_ sender: Any) { // start: true, stop: false, reset: true setButtonEanble(start: true, stop: false, reset: true) if let startTime = self.startTime { self.elapsedTime += Date.timeIntervalSinceReferenceDate - startTime } self.timer.invalidate() } @IBAction func resetTimer(_ sender: Any) { // start: true, stop: false, reset: false setButtonEanble(start: true, stop: false, reset: false) self.startTime = nil self.timerLavel.text = "00:00:00:00:00:00:00" self.elapsedTime = 0.0 } }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。