我正在使用AFNetworking库,它使用块来处理结果,如下所示:
[httpClient HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *op, id response) {
//success clock
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//error block
}]
有没有代码块使用它的方法?例如使用委托?如下所示:
[httpClient HTTPRequestOperationWithRequest:request delegate:self]
并在自课中:
-(void)afhttpSuccess:(AFHTTPRequestOperation*)op Response:(id)response {
//success method
}
-(void)afhttpError:(AFHTTPRequestOperation*)op Response:(NSError*)error {
//error method
}
答案 0 :(得分:3)
不确定为什么委托+选择器范例会更好,但我做了this library, which eases the transition from ASI, which has that pattern。
或者,您始终可以在成功/失败回调中调用成功/失败方法。