2012-03-29 62 views
-1

我在iPhone和內部使用的塊,我只是顯示一個標題和文字UIAlertView
問題是警報視圖有時會出現很長時間。 在其他地區的工作正常。 任何人都可以建議我可能是什麼原因?UIAlertView在一段時間後來臨

+1

後一些代碼。 – Hiren 2012-03-29 05:40:06

+0

它在哪裏運行......你需要發佈一些代碼。 – Jamie 2012-03-29 05:42:46

回答

3

必須從主線程處理UI *元素。如果您使用塊在後臺運行某些內容,則會在主線程的dispatch_queue中包裝所有對UI*的調用。

這樣的:

dispatch_async(myQueue, ^{ 
    // do something in background 
    dispatch_async(dispatch_get_main_queue(), ^{ 
     // Interaction with User Interface Elements on the main thread... 
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Foo" message:@"Bar" delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil]; 
     [alert show]; 
    }); 
}); 
+2

或者,'[self performSelectorOnMainThread:@selector(MethodThatShowsAlert :) withObject:IfAnything waitUntilDone:NO];' – tipycalFlow 2012-03-29 06:09:37

+0

非常感謝。有效。 – iVipS 2012-03-29 06:28:31