我使用回調來開發BLEModule。 以下是檢查電源的簡單代碼。 它在ViewDidLoad中運行良好。 但是,爲什麼代碼在@IBAction中沒有響應?Swift - 點擊後回撥電話
class ViewController: UIViewController {
var ble = BLEManager.sharedInstance
override func viewDidLoad() {
super.viewDidLoad()
ble.confirmPower { (result) in
print(result) //true or false
}
}
@IBAction func checkBtn(_ sender: Any) {
print("power")
ble.confirmPower { (result) in
print(result) //non-response
}
}
}
我使用回調開發BLEModule。 以下是檢查電源的簡單代碼。 它在ViewDidLoad中運行良好。 但是,爲什麼代碼在@IBAction中沒有響應?
點擊了按鈕後,您是否驗證過「電源」打印到控制檯?如果沒有,你可能忘了將你的Storyboard中的按鈕連接到'ViewController'代碼中的'checkBtn(_ :)'方法。 – RobertJoseph