标签:
int main(int argc, const char * argv[]) { Person *person = [[Person alloc]init]; Ticker *ticker = [[Ticker alloc]init]; person.delegate=ticker; [person buyTicker]; return 0; } Person.h @interface Person : NSObject @property (nonatomic, strong) id<TickerDelegate> delegate; -(void)buyTicker; @end Person.m @implementation Person -(void)buyTicker { int num = [_delegate getTickerNumber]; double price = [_delegate getTickePrcie]; NSLog(@"%d, %f", num, price); } @end Ticker.h @interface Ticker : NSObject<TickerDelegate> @end Ticker.m @implementation Ticker -(double)getTickePrcie { return 50; } -(int)getTickerNumber { return 10; } @end TickerDelegate.h @protocol TickerDelegate <NSObject> -(int)getTickerNumber; -(double)getTickePrcie; @end
标签:
原文地址:http://www.cnblogs.com/jsnan/p/4340849.html