我需要在某些代码在后台执行时显示警报视图。为此,我实现了以下代码。如何在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