1.要自定义一个Operation 首先要创建一个继承于NSOperation的类。
2.在创建好的类的.h文件声明自定义的方法:-(instancetype)initWithDownLoadMessage:(NSString *)url;
3.在创建好的类的.m文件实现自定义方法:
-(instancetype)initWithDownLoadMessage:(NSString *)url{
self =[super init];
if (self) {
URLString =url;
}
return self;
}
4.然后我们只需要在需要用到的类里面导入之前创建号的类:#import “DownLoadOperation.h"
5.初始化类的对象,应用类方法:
imageview =[[UIImageView alloc]initWithFrame:self.view.frame];
[self.view addSubview:imageview];
DownLoadOperation *download =[[ DownLoadOperation alloc]initWithDownLoadMessage:@"http://file.bmob.cn/M01/37/F1/oYYBAFXdo8yAFY8QAABIFt81XEM849.png"];