一,协议的定义
@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
三,调用协议
@interface testdiaoyong : NSObject{
id<test> testp;
}
-(void)setpoco:t;
-(void)setlen;
@end
@implementation testdiaoyong
@synthesize testp;
//协议t可以不负类型
-(void)setpoco:t{
self.testp=t;
}
-(void)start{
[testp testpocol:99];
}
@end
本文详细解析了iOS开发中的关键技术和Swift编程语言的高级特性,包括UI设计、性能优化、错误处理和协程编程等内容。通过实战案例,为开发者提供了一站式的技术解决方案。
1万+

被折叠的 条评论
为什么被折叠?



