iOS 委托模式(2)
来源:未知 责任编辑:责任编辑 发表时间:2014-02-02 17:44 点击:次
p>
p>-(void)willBuy;
p>
p>@end
p>
p>#import <Foundation/Foundation.h>
p>
p>@protocol MyDelegate <NSObject>
p>
p>-(void)buyIphone:(NSString*)iphoneType;
p>
p>@end
p>
p>@interface Customer : NSObject
p>
p>@property(nonatomic,assign)id<MyDelegate> delegate;
p>
p>-(void)willBuy;
p>
p>@end
p>Customer.m
p>
p>
p>
p>[cpp]
p>#import "Customer.h"
p>
p>@implementation Customer
p>
p>@synthesize delegate;
p>
p>-(void)willBuy {
p> [delegate buyIphone:@"Iphone5"];
p>}
p>
p>@end
p>
p>#import "Customer.h"
p>
p>@implementation Customer
p>
p>@synthesize delegate;
p>
p>-(void)willBuy {
p> [delegate buyIphone:@"Iphone5"];
p>}
p>
p>@end
p>Businessman.h
p>
p>
p>[cpp]
p>#import <Foundation/Foundation.h>
p>#import "Customer.h"
p>
p>@interface Businessman : NSObject<MyDelegate>
p>
p>@end
p>
p>#import <Foundation/Foundation.h>
p>#import "Customer.h"
p>
p>@interface Businessman : NSObject<MyDelegate>
p>
p>@end
p>Businessman.m
p>
p>
p>[cpp]
p>#import "Businessman.h"
p>
p>@implementation Businessman
p>
p>-(void)buyIphone:(NSString *)iphoneType {
p> NSLog(@"There is an Iphone store,we have %@",iphoneType);
p>}
p>
p>
p>@end
p>
p>#import "Businessman.h"
p>
p>@implementation Businessman
p>
p>-(void)buyIphone:(NSString *)iphoneType {
p> NSLog(@"There is an Iphone store,we have %@",iphoneType);
p>}
p>
p>
p>@end
p>main.m
p>
p>
p>[cpp]
p>#import <Foundation/Foundation.h>
p>
p>#import "Customer.h"
p>#import "Businessman.h"
p>
p>int main(int argc, const char * argv[])
p>{
p>
p> @autoreleasepool {
p>
p> // insert code here...
p> Customer *customer = [[Customer alloc]init];
p> Businessman *businessman = [[Businessman alloc]init];
p> customer.delegate = businessman;
相关新闻>>
- 发表评论
-
- 最新评论 进入详细评论页>>
今日头条
更多>>您可能感兴趣的文章
- iphone开发基础三和c语言混编
- iPhone开发 调用阿asp.net程序的webservice
- iPhone开发 文件的增加删除查询
- 深入理解iPhone静态库(手把手教你iphone开发
- (iOS-iap防护)验证用户付费收据,拒绝iap
- iphone-使用TextField及关闭键盘(useing TextField for in
- ios 关于UITableView UITableViewCellAccessoryCheckmark 混乱的
- iOS文件存磁盘的设想
- Cocoa Core Competencies 的Object creation 和IOS面试题示例
- ios 时间定时器 NSTimer应用demo
新闻点评
新闻关注排行榜
热门推荐
最新推荐