我想創建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