import UIKit
import AVFoundation
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
//'this is the code that i am using for my project'
@IBOutlet weak var progressBar: UIProgressView!
@IBOutlet weak var titleLabel: UILabel!
let coffeeTimes = ["Decaf": 5]
var timer = Timer()
var player: AVAudioPlayer!
var totalTime = 0
var secondsPassed = 0
@IBAction func coffeeSelected(_ sender: UIButton) {
timer.invalidate()
let coffee = sender.currentTitle!
totalTime = coffeeTimes[coffee]!
progressBar.progress = 0.0
secondsPassed = 0
titleLabel.text = coffee
timer = Timer.scheduledTimer(timeInterval: 1.0, target:self, selector: #selector(updateTimer), userInfo:nil, repeats: true)
}
@objc func updateTimer() {
if secondsPassed < totalTime {
secondsPassed = 1
progressBar.progress = Float(secondsPassed) / Float(totalTime)
print(Float(secondsPassed) / Float(totalTime))
} else {
timer.invalidate()
titleLabel.text = "check coffee"
let url = Bundle.main.url(forResource: "alarm_sound", withExtension: "mixkit-warnin...uzzer-991(1)")
player = try! AVAudioPlayer(contentsOf: url!)
player.play()
}
}
}
“這是我用于我的專案的代碼。”
uj5u.com熱心網友回復:
該錯誤幾乎總是意味著您在 Storyboard 或 XIB 中的 IBOutlet 鏈接已損壞。(故事板指向它指向的類中不存在的出口。)
鑒于錯誤提到了一個名為“tittleLabel”的 IBOutlet,并且您的代碼有一個名為“titleLabel”的插座,這似乎是您崩潰的可能原因。
我建議打開包含您的ViewController類的 Storyboard ,并使用連接檢查器仔細檢查所有插座。如果您發現了錯誤的,請將其洗掉,然后從您的代碼中按住 Control 鍵拖動回故事板中的插座以連接正確的插座。
uj5u.com熱心網友回復:
當標簽或按鈕的連接出現問題時,就會出現這種型別的錯誤。在 Storyboard 中,選擇您的視圖控制器并檢查您的連接檢查器,如下圖所示:

在這里檢查 titleLabel 的連接,首先洗掉連接并再次與您的 swift 類檔案建立連接。
希望這有效。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/399932.html
