我使用回调来开发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