我想创建NSInvocationOperation选择这样,它应该调用对象的方法使用参数NSInvocationOperation定义使用参数
- (void) getImages: (NSRange) bounds
{
NSOperationQueue *queue = [NSOperationQueue new];
NSArray * params = [NSArray arrayWithObjects:
[[NSNumber alloc] initWithInt: bounds.location],
[[NSNumber alloc] initWithInt: bounds.length]];
NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self
selector:@selector(loadImagesWithOperation)
object:params];
[queue addOperation:operation];
[operation release];
}
- (void) loadImagesWithOperation:(NSArray*)bounds {
NSLog(@"loadImagesWithOperation");
}
此代码与EXC_BAD_ACCESS崩溃。如果我改变这个功能的定义
- (void) loadImagesWithOperation {
NSLog(@"loadImagesWithOperation");
}
一切都会好起来的。我试图使用@selector的代码块,如@selector(loadImagesWithOperation :)和@selector(loadImagesWithOperation:bounds :),但未成功。
用params来定义选择器和函数的正确方法是什么?
感谢。
发布崩溃的回溯 – bbum 2011-01-25 17:41:30