Objective-C在performSelectorOnMainThread中传递带参数的消息:

时间:2012-08-14 17:34:55

标签: objective-c ios5 objective-c-blocks performselector

当传入@selector的方法有参数时,需要有关语法的帮助。谢谢!

//This works
dispatch_async(kBgQueue, ^{ 

 [self performSelectorOnMainThread:@selector(hydrateList) withObject:nil waitUntilDone:YES];   

});



//But what about when the method in the selector has arguments?
//This is incorrect, syntactically
  dispatch_async(kBgQueue, ^{ 

     [self performSelectorOnMainThread:@selector(hydrateListForCategory:self.categorySelected) withObject:nil waitUntilDone:YES];
  });

2 个答案:

答案 0 :(得分:3)

提示:这就是“withObject:”部分存在的原因。

提示2:Apple的框架文档非常好。

提示3:

[self performSelectorOnMainThread:@selector(hydrateListForCategory:) withObject:self.categorySelected waitUntilDone:YES];

答案 1 :(得分:1)

[self performSelectorOnMainThread:@selector(hydrateListForCategory:) withObject:self.categorySelected waitUntilDone:YES];