[self performSelectorOnMainThread:@selector(customFoo:) withObject:obj waitUntilDone:YES];
和呼籲
[self customFoo:obj];
據我所知,如果第二個是在主線程調用,沒有他們兩個有什麼區別...是對?
他們兩人之間的基本區別是什麼?
[self performSelectorOnMainThread:@selector(customFoo:) withObject:obj waitUntilDone:YES];
和呼籲
[self customFoo:obj];
據我所知,如果第二個是在主線程調用,沒有他們兩個有什麼區別...是對?
他們兩人之間的基本區別是什麼?
運行時行爲是相同的。但是編譯代碼時會有差異:如果定義了方法customFoo:
,則第二個代碼只會編譯。
performSelector:向接收方發送指定的消息並返回消息的結果。
PerformSelector用於調用方法,只要你想執行,這意味着你有選項來選擇不同的選項來執行特定的任務(方法)示例...
– performSelector:withObject:afterDelay: // will execute method after specific delay..
– performSelector:withObject:afterDelay:inModes:
– performSelectorOnMainThread:withObject:waitUntilDone:
– performSelectorOnMainThread:withObject:waitUntilDone:modes:
– performSelector:onThread:withObject:waitUntilDone:
– performSelector:onThread:withObject:waitUntilDone:modes:
– performSelectorInBackground:withObject:
//在後臺執行任務。所以,你ManinThread(應用程序)將不會停止responding..like多線程..
凡直接法([self customFoo:obj];
)將不會執行任務提供選擇..
For more and detailed explanation visit this reference..
希望,這將有助於你...