-[NSInvocationOperation initWithTarget:selector:object:]
只接受一个对象作为将要调用的方法的参数传递。我想使用两个参数;我怎样才能做到这一点?
这是我的代码:
- (void)loadImage:(NSURL *)imageURL
{
NSOperationQueue *queue = [NSOperationQueue new];
NSInvocationOperation *operation = [[NSInvocationOperation alloc]
initWithTarget:self
selector:@selector(requestRemoteImage:)
object:imageURL];
[queue addOperation:operation];
}
- (void)requestRemoteImage:(NSURL *)imageURL
{
NSData *imageData = [[NSData alloc] initWithContentsOfURL:imageURL];
UIImage *image = [[UIImage alloc] initWithData:imageData];
[self performSelectorOnMainThread:@selector(placeImageInUI:) withObject:image waitUntilDone:YES];
}