我正在更新一些遗留目标C代码,以便能够在OSX 10.13下编译。遗留代码有效,大多数更新代码也可以,除了需要处理didFinishPlaying函数的NSSoundDelegate。委托方法未被调用。委托方法包含在名为MyClass的类中。这是相关的代码。
在MyClass.h中:
@class MyClass;
@protocol MyClass <NSObject>
@optional
- (void)sound:(NSSound *)sound didFinishPlaying:(BOOL)flag;
@end
@interface MyClass : NSObject <NSSoundDelegate>
{
}
@property (nonatomic, assign) id <NSSoundDelegate> delegate;
- (void)sound:(NSSound *)sound didFinishPlaying:(BOOL)flag;
- (id) init;
@end
然后在MyClass.m中:
@implementation MyClass
@synthesize delegate;
- (void)sound:(NSSound *)sound didFinishPlaying:(BOOL)flag
{
if (flag) {
[[NSNotificationCenter defaultCenter] postNotificationName:@"handleNSSoundDidFinishPlaying" object:sound];
}
}
- (id)init
{
MyClass *thePointer;
self = [super init];
if (self) {
thePointer = self;
self.delegate = (id)thePointer;
isInitialized = NO;
isClosing = NO;
[self set_currentSounds:[NSMutableArray arrayWithCapacity:0]];
}
return self;
}
@end
任何人都能看到我失踪的东西吗?
答案 0 :(得分:0)
我认为您应该通知委托对象,如:
if([_delegate respondsToSelector:@selector(sound: didFinishPlaying:)])
[_delegate sound:self didFinishPlaying:_flag];
希望这会对你有所帮助。
答案 1 :(得分:0)