Reputation: 673
I have the PGMidi.h
with the following delegate
@protocol PGMidiSourceDelegate
- (void) midiSource:(PGMidiSource*)input midiReceived:(const MIDIPacketList *)packetList;
Then in my viewController.m
I simply want to get an NSLog
when the delegate is called so
@interface viewController () <PGMidiDelegate, PGMidiSourceDelegate>
@end
@implementation viewController;
- (void) midiSource:(PGMidiSource*)midi midiReceived:(const MIDIPacketList *)packetList
{
NSLog(@"test");
}
I know that the delegate is working because in the PGMidi
Class I also put
- (void) midiSource:(PGMidiSource*)midi midiReceived:(const MIDIPacketList *)packetList
{
NSLog(@"test");
}
and it works.
But for some reason it is not communicating with the viewController.m. I am also declaring the @PGMidi class in the header. But perhaps I have to import the entire PGMidi.h?
Upvotes: 0
Views: 207
Reputation: 11595
Do you include @end
to conclude your code @protocol PGMidiSourceDelegate
in PGMidi.h? Also make sure in viewController.h that you say @interface viewController : (parentClass) <PGMidiSourceDelegate
. (parentClass) is whatever class viewController inherits from. Basically, either your problem is you forgot the @end or you didn't specify that viewController is a delegate of PGMidi.h.
Upvotes: 0
Reputation: 16714
In your PGMidi.h you should actually declare a delegate property, i.e.
@property (nonatomic, assign) id<PGMidiSourceDelegate> delegate;
Make sure to synthesize
that property in your PGMidi.m file. Then, in your PGMidi.m you should be doing this:
-(void) midiSource:(PGMidiSource*)midi midiReceived:(const MIDIPacketList *)packetList {
[delegate midiSource:midi midiReceived:packetList];
}
You also need to actually set the view controller as the delegate of your PGMidi object:
myPGMidi.delegate = myViewController;
Upvotes: 1