委托代理和协议的使用

@protocol ADelegate<NSObject>
	- (void) methods;
@end

@interface ClassA:NSObject
- (void) Amethods
@property(assign, non atomic) id <ADelegate>delegate;
@end


@implementation ClassA
- (void) Amethods
{
   [delegate methods];

   ClassB *classB = (ClassB *)delegate;
   [classB Bmethods];
}
@end


@interface ClassB<ADelegate>
- (void) Bmethods;
@end

@implementation ClassB
-(id)init
{
	ClassA *A = [[ClassA alloc] init];
	A.delegate = self;
}

- (void) Bmethods
{
   //do something
}

- (void) methods
{
   //do something
}
@end

  

posted @ 2012-12-07 13:09  hellocby  阅读(251)  评论(0编辑  收藏  举报