我试图使用协议从我的视图控制器类的swift类中触发一个函数。
@objc protocol KestrelDeviceConnectDelegate: AnyObject {
func readingIsOver()
}
class KestrelDeviceConnect: NSObject {
weak var delegate: KestrelDeviceConnectDelegate?
func timerAction() {
timerCounter += 1
if(timerCounter >= 20){
progressHUD.hide()
timerCounter = 0
timer.invalidate()
self.delegate?.readingIsOver()
//present kestrel alert
}
}
}
在视图控制器类viewdidload
KestrelDeviceConnect *bluetoothManager = [[KestrelDeviceConnect alloc]init];
bluetoothManager.delegate = self;
我想从我的快捷类中调用的功能
- (void)readingIsOver {
[[self logConditionsButton] setHidden:NO];
}
答案 0 :(得分:1)
您需要通过将bluetoothManager
设置为实例变量
KestrelDeviceConnect *bluetoothManager;
bluetoothManager = [[KestrelDeviceConnect alloc]init];