我有以下代碼...dispatch_async不工作的所有時間
-(void) SetSerialNumber
{
NSLog(@"SetSerialNumber");
NSString *serialNum = textFieldSecond.text;
if (textFieldSecond.text == nil) {
[self performSelectorOnMainThread:@selector(display:) withObject:@"Please Enter the serial number" waitUntilDone:YES];
return;
}
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), ^(void){
NSString* response;
[self performSelectorOnMainThread:@selector(display:) withObject:@"Sending Set Serial Num request" waitUntilDone:YES];
[[testApp sharedClass] SetSerNumber:serialNum];
[self performSelectorOnMainThread:@selector(display:) withObject:@"Waiting for Response..." waitUntilDone:YES];
response = [[Process sharedProcess] readAndProcessData:ACK];
[self performSelectorOnMainThread:@selector(display:) withObject:rpcresponse waitUntilDone:YES];
});
}
的方法display:
將郵件到UITextView
。
當按下按鈕時,我調用這個函數。有時dispatch_async塊沒有被調用。它只是通過它而落下。但是,我可以看到每次都打印日誌消息。
任何人都可以請分享可能會導致這種情況嗎?
如果按下按鈕時調用此函數,爲什麼要調用第一個'performSelectorOnMainThread:withObject:waitUntilDone:'? –
好吧,我不應該使用performSelectorOnMainThread:,它只是爲用戶的消息,沒有什麼比這更多。 –