Objective-C学习文档之协议使用方法是本文要介绍的内容,主要是来了解并学习Objective-C中协议的问题,具体内容来看本文内容详解。
一、协议的定义
@protocol test -(void) testpocol:(int)t; @end
二、协议的继承
h头文件
#import “test.h” //导入协议
@interface testViewController:UIViewController <test>{
//id<test> testp;
} m实现文件
@implementation testViewController
-(void)viewDidLoad{
[super viewDidLoad];
//调用实现方法的类
testdiaoyong *td=[[testdiaoyong alloc] init];
td.testd=self; 把当前实现协议的类对象赋给需要使用的地方
//也可以使用下面的方法传递协议
[td setpoco:self]
}
-(void) testpocol:(int)s{
NSLog(@"testpocol.........%d",s);
}
@end 三、调用协议