【发布时间】:2023-03-06 01:28:01
【问题描述】:
我有两个课程A 和B。我有一次删除将变量从A 传递到B。我尝试让另一个代表从B 到A,这样我就可以从B 控制A。我试图创建另一个委托,但它不起作用。由于我已经在 B.h 中导入了 A.h,因此我无法在 A.h 中导入 B.h。我应该怎么做才能设置两种方式自定义委托?
啊.h
@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
这是一种委托方式。
我试图在 B.h 中拥有类似的东西:
@protocol SceneDelegate <NSObject>
-(void)cancel_thread;
@end
@interface HelloScene : SKScene <SoundDetectDelegate>
@property(nonatomic, strong) SoundDetect* sd;
@property(nonatomic, strong)Song* song;
@end
但我不能在 A.h. 中拥有 @interface SoundDetect : NSObject <SceneDelegate>
将变量从B 传递到A 的主要目的是我想将变量发送到A,以便A 可以取消其当前线程。
谢谢
【问题讨论】:
-
你想要什么类型的控制,或者你想从 B 到 A 具体做什么?
标签: ios objective-c multithreading delegates