NSOperation的倍数参数?

kee*_*you 0 iphone cocoa-touch nsoperation nsoperationqueue nsinvocationoperation

我在我的应用程序中使用NSOperationQueue,我想为我的操作设置多个参数,我该怎么做?

   NSOperationQueue *queue = [[[NSOperationQueue alloc] init] autorelease];
   NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(methodCall) object:nil];
  [queue addOperation:operation];
  [operation release];
Run Code Online (Sandbox Code Playgroud)

ros*_*eau 6

您必须使用所需的数据创建数组或字典.

例如:

NSOperationQueue *queue = [[[NSOperationQueue alloc] init] autorelease];
NSDictionary *argumentDictionary = [NSDictionary dictionaryWithObjectsAndKeys:object1, @"Object1Key", object2, @"Object2Key", nil];
NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(methodCall:) object:argumentDictionary];
[queue addOperation:operation];
[operation release];
Run Code Online (Sandbox Code Playgroud)

并且- (void)methodCall:(NSDictionary *)argumentDictionary您可以使用该字典中存储的对象和值.