0
如何使用performSelector:onThread:withObject:waitUntilDone:?在onthread中,我必須使用其他線程而不是主線程。如何創建其他線程?給我一些示例代碼。如何使用performSelector:
如何使用performSelector:onThread:withObject:waitUntilDone:?在onthread中,我必須使用其他線程而不是主線程。如何創建其他線程?給我一些示例代碼。如何使用performSelector:
除非你有一個線程池來管理,它更容易使用-performSelectorInBackground:…
:
[object performSelectorInBackground:@selector(method:) withObject:foo];
如果你要創建一個線程,使用
NSThread* thread = [[NSThread alloc] init];
[object performSelector:@selector(method:)
onThread:thread
withObject:foo
waitUntilDone:YES];
[thread release];
感謝您的回覆。但這不起作用。方法沒有調用。 – Allen 2010-05-13 12:40:59
@艾倫:你的代碼是什麼? – kennytm 2010-05-13 13:38:30
您好Kenny,您需要在目標線程中運行一個運行循環,以便處理'performSelector:'輸入源。所以我不認爲你的代碼工作... – Yuji 2010-05-13 15:25:30