我注意到上的UIImageView的AFNetworking和SDWebImage类具有相同的方法名。
AFNetworking:
- (void)setImageWithURL:(NSURL *)url {
[self setImageWithURL:url placeholderImage:nil];
}
- (void)setImageWithURL:(NSURL *)url
placeholderImage:(UIImage *)placeholderImage
{
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPShouldHandleCookies:NO];
[request addValue:@"image/*" forHTTPHeaderField:@"Accept"];
[self setImageWithURLRequest:request placeholderImage:placeholderImage success:nil failure:nil];
}
- (void)setImageWithURLRequest:(NSURLRequest *)urlRequest
placeholderImage:(UIImage *)placeholderImage
success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image))success
failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure
{
...
}
和SDWebImage
- (void)setImageWithURL:(NSURL *)url
{
[self setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:nil];
}
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder
{
[self setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:nil];
}
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options
{
[self setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:nil];
}
...
在Xcode中,当我命令点击它重定向我到AFNetworking方法和反之亦然SDWebImage方法。
其行为我可以期待在哪里? 我应该只包括我想用它在一个类中的相应类别的头? 如果同一类需要使用类的两种实现?
另一个相关的问题:“ 如果两个ObjC类覆盖同样的方法,会发生什么? ”是不太一样的,是因为AFNetworking和SDWebImage都被添加到类别相同类别不是一个子类别。 在这种情况下,只有当阶级正在使用和2类似乎是相互冲突的。