我有PGMidi.h
以下代理人
@protocol PGMidiSourceDelegate
- (void) midiSource:(PGMidiSource*)input midiReceived:(const MIDIPacketList *)packetList;
然后在我的viewController.m
中,我只想在调用委托时获得NSLog
@interface viewController () <PGMidiDelegate, PGMidiSourceDelegate>
@end
@implementation viewController;
- (void) midiSource:(PGMidiSource*)midi midiReceived:(const MIDIPacketList *)packetList
{
NSLog(@"test");
}
我知道代表正在工作,因为在PGMidi
班级中我也放了
- (void) midiSource:(PGMidiSource*)midi midiReceived:(const MIDIPacketList *)packetList
{
NSLog(@"test");
}
它有效。
但由于某种原因,它没有与viewController.m通信。我也在标题中声明了@PGMidi类。但也许我必须导入整个PGMidi.h?
答案 0 :(得分:1)
在您的PGMidi.h中,您实际上应该声明一个委托属性,即
@property (nonatomic, assign) id<PGMidiSourceDelegate> delegate;
确保PGMidi.m文件中的synthesize
该属性。然后,在你的PGMidi.m中你应该这样做:
-(void) midiSource:(PGMidiSource*)midi midiReceived:(const MIDIPacketList *)packetList {
[delegate midiSource:midi midiReceived:packetList];
}
您还需要将视图控制器实际设置为PGMidi对象的委托:
myPGMidi.delegate = myViewController;
答案 1 :(得分:0)
是否包含@end
在PGMidi.h中结束代码@protocol PGMidiSourceDelegate
?还要在viewController.h中确保你说@interface viewController : (parentClass) <PGMidiSourceDelegate
。 (parentClass)是viewController继承的任何类。基本上,要么你的问题是忘了@end,要么你没有指定viewController是PGMidi.h的委托。