我需要在某些代碼在後臺執行時顯示警報視圖。爲此,我實現了以下代碼。如何在ipad應用程序的後臺線程中顯示UIAlertView?
//this is loading alert
-(void)showAlert:(NSString *)message {
// UIAlertView *alert;
alert11 = [[UIAlertView alloc] initWithTitle:@"Updates" message:message delegate:self
cancelButtonTitle:@"OK" otherButtonTitles: nil];
#ifndef IOS5_1
[alert11 autorelease];
#endif
[alert11 show];
}
-(void) showUpdates1:(NSString *)data {
isUpdating = true;
VideoBrowserAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
[appDelegate initApplicationDefaults];
[self performSelectorOnMainThread:@selector(showAlert:)
withObject:@"Please wait while Updating the view...."
waitUntilDone:YES];
[appDelegate openExhibitView1];
//this is update completed alert
[VideoBrowserAppDelegate addUpdateLog:@"Update is completed" showLog:TRUE calledFrom:nil];
}
不過,雖然即將performSelectorOnMainThread(..),顯示警報,但它消失在第二位。之後openExhibitView1()完全執行,並再次更新警報顯示正確。當我們點擊更新警報的OK按鈕時,再次顯示加載警報。但這不公平。我需要顯示加載警報,直到openExhibitView1()在後臺執行,除非我們點擊確定按鈕。請幫助我如何能達到這一點。
第一個消失可能是因爲第二個出現。這是alertView屬性..第一個隱藏第二個顯示,然後當第二個取消,然後第一個回彈。 – rptwsthi
也是你的問題是錯的。你不能在後臺線程上執行UI thibgs。 –
正如@rptwsthi所說,所以您需要防止應用程序同時顯示多個警報 – Wain