iOS 委托模式(4)
来源:未知 责任编辑:责任编辑 发表时间:2014-02-02 17:44 点击:次
p>#import "Boss.h"
p>@interface Secretary : NSObject <MissionDelegate>
p>
p>@end
p>
p>#import <Foundation/Foundation.h>
p>#import "Boss.h"
p>@interface Secretary : NSObject <MissionDelegate>
p>
p>@end
p>Secretary.m
p>
p>
p>
p>[cpp]
p>#import "Secretary.h"
p>
p>@implementation Secretary
p>
p>-(void)draftDocuments {
p> NSLog(@"Secretary draft documents");
p>}
p>
p>-(void)tellPhone {
p> NSLog(@"Secretary tell phone");
p>}
p>
p>@end
p>
p>#import "Secretary.h"
p>
p>@implementation Secretary
p>
p>-(void)draftDocuments {
p> NSLog(@"Secretary draft documents");
p>}
p>
p>-(void)tellPhone {
p> NSLog(@"Secretary tell phone");
p>}
p>
p>@end
p>main.m
p>
p>
p>[cpp]
p>
p>#import <Foundation/Foundation.h>
p>#import "Secretary.h"
p>#import "Boss.h"
p>
p>int main(int argc, const char * argv[])
p>{
p>
p> @autoreleasepool {
p>
p> // insert code here...
p> Boss *boss = [[Boss alloc] init];
p> Secretary *secretary = [[Secretary alloc] init];
p>
p> boss.delegate = secretary;
p> [boss manage];
p> }
p> return 0;
p>}
p>
p>#import <Foundation/Foundation.h>
p>#import "Secretary.h"
p>#import "Boss.h"
p>
p>int main(int argc, const char * argv[])
p>{
p>
p> @autoreleasepool {
p>
p> // insert code here...
p> Boss *boss = [[Boss alloc] init];
p> Secretary *secretary = [[Secretary alloc] init];
p>
p> boss.delegate = secretary;
p> [boss manage];
p> }
p> return 0;
p>}
p>三、这个例子两个view视图之间传递参数
p>
p>定义一个MyView类,在这个视图中添加了一个button,button的事件响应他本身不处理,而让被委托类去处理,所以它就是委托类。
p>
p>在主视图中,添加一个MyView类的实例对象,设置该实例对象的代理为self,所以它就是委托类了。
相关新闻>>
- 发表评论
-
- 最新评论 更多>>