-3
當傳遞給@selector的方法有參數時,需要語法方面的幫助。謝謝!Objective-C在performSelectorOnMainThread中傳遞帶參數的消息:
//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];
});
搜索該方法和閱讀文檔。 [NSObject文檔](https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/nsobject_Class/Reference/Reference.html#//apple_ref/occ/instm/NSObject/performSelectorOnMainThread:withObject :waitUntilDone :) – MechEthan 2012-08-14 17:40:14