I'm new to iOS development, and I'm playing with an interface trying to understand some concepts. The provided SDK(which is compiled and I can't do anything to it) has the following definitions:
@class HRMonitor;
@protocol HRMonitorDelegate
- (void) hrmon: (HRMonitor*) mon heartRateUpdate: (double) hr;
// And others
@end
@interface HRMonitor : NSObject <NSStreamDelegate>{
}
-(id) init: (id) _delegate;
-(void)startup;
Does anyone have idea how can I use the heartRateUpdate
method defined in the protocol HRMonitorDelegate
? From what I read in the iOS Developer Library, I have to have an interface that conforms to the Delegate like HRMonitor : NSObject <HRMonitorDelegate>
to call methods in the protocol. But that's not provided in the API.
Or can I use the init
method? But then how should I pass the _delegate
?
conform your interface to the delegate
init HRMonitor, passing your interface instance as the _delegate
then the - (void) hrmon: (HRMonitor*) mon heartRateUpdate: (double) hr of you interface will be called
make a interface conforms to the delegate, and call the method of it when you need, remember to check the delegate is not nil and response to the method you want to call
@interface YourClass : NSObject <HRMonitorDelegate> @implementation HRMonitor -(void)someMethod { HRMonitor monitor = [HRMonitor alloc] init:self]; } - (void) hrmon: (HRMonitor*) mon heartRateUpdate: (double) { }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.