美文网首页
关于delegate的使用

关于delegate的使用

作者: xjqDreams | 来源:发表于2017-03-22 17:44 被阅读0次

        使用delegate在设计模式中是多个对象组合使用,当对象1发生有数据发生改变时,使用delegate进行通知。

创建过程:

1.在通用类中创建delegate

@protocol SyncAndLoadDelegate

- (void)onSyncHealthEnd;

- (void)onSyncSleepEnd;

- (void)onSyncHeartRateEnd;

- (void)onSyncSportEnd;

- (void)onLoadSportStart;

- (void)onLoadSportEnd;

- (void)onConnectStateChange;

@end

2.在类的@interface NewfeatureController中<代理名称>,在类的viewDidLoad中注册代理。

@interface NewHomeViewController : RootViewController<SyncAndLoadDelegate>

3.在注册类中发生相应变化的地方进行代理的通知与方法的调用。

BluetoothDelegate *bluetoothDelegate = [BluetoothDelegate sharedDelegate];        NSMutableArray *delegates = [bluetoothDelegate changeSyncAndLoadNumbers];        for (int i=0; idelegate = [delegates objectAtIndex:i];

[delegate onConnectStateChange];

}

相关文章

网友评论

      本文标题:关于delegate的使用

      本文链接:https://www.haomeiwen.com/subject/vpaonttx.html