我有两个类A
和 B
。我有一个删除来传递 A
中的变量至 B
。我尝试让另一位来自 B
的委托(delegate)至 A
,这样我就可以控制A
来自 B
。我尝试创建另一个委托(delegate),但它不起作用。由于我已经在 B.h 中导入了 A.h,因此无法在 A.h 中导入 B.h。我应该怎么做才能设置两种方式的自定义委托(delegate)?
啊啊
@protocol SoundDetectDelegate <NSObject>
-(void)update_from_sound: (SKSpriteNode*) node;
@end
@interface SoundDetect : NSObject
@property (nonatomic, weak) id <SoundDetectDelegate> delegate;
+ (id)sharedInstance;
-(void)beat;
@end
B.h
@interface HelloScene : SKScene <SoundDetectDelegate>
@property(nonatomic, strong) SoundDetect* sd;
@property(nonatomic, strong)Song* song;
@end
这是单向委托(delegate)。
我尝试过类似 B.h 的内容:
@protocol SceneDelegate <NSObject>
-(void)cancel_thread;
@end
@interface HelloScene : SKScene <SoundDetectDelegate>
@property(nonatomic, strong) SoundDetect* sd;
@property(nonatomic, strong)Song* song;
@end
但我不能有@interface SoundDetect : NSObject <SceneDelegate>
在啊
从 B
传递变量的主要目的至 A
是我想发送一个变量到 A
,所以 A
可以取消其当前线程。
谢谢
最佳答案
您需要做的是使用返回类型为 BOOL 的 block 来通知是否应该取消它,而不是使用委托(delegate)。
关于ios两种方式自定义委托(delegate),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28059813/