オブジェクトのメソッドをparamsで呼び出す必要があるように、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(loadImagesWithOperation:)や@selector(loadImagesWithOperation:bounds:)のような@selectorのコード ブロックで別の構文を使用しようとしましたが、成功しませんでした。
パラメータを使用してセレクタと関数を定義する正しい方法は何ですか?
ありがとう。