Ipad 线程错误

Ipad 线程错误,ipad,Ipad,要检查有效登录, 我从Webservice获取数据并显示进度, 我在UIAlertView内显示UIIndicatorView 问题是: 在进程中,当按下IPad设备的Home(主页)按钮时,我的应用程序关闭,第二次尝试启动应用程序时(显示黑色屏幕),应用程序未启动。 我怎样才能解决这个问题 我的代码是: -(NSMutableString*) getLoginMessage:(NSString*) UserName : (NSString *) Password : (NSString *)

要检查有效登录, 我从Webservice获取数据并显示进度, 我在UIAlertView内显示UIIndicatorView 问题是: 在进程中,当按下IPad设备的Home(主页)按钮时,我的应用程序关闭,第二次尝试启动应用程序时(显示黑色屏幕),应用程序未启动。 我怎样才能解决这个问题

我的代码是:

-(NSMutableString*) getLoginMessage:(NSString*) UserName : (NSString *) Password : (NSString *) url

{

[NSThread detachNewThreadSelector:@selector(showAlertMethod) toTarget:self withObject:nil];
@try
{
NSArray *Keys =[[NSArray alloc] initWithObjects:@"LoginName",@"PassWord",nil];
NSArray *KeyValue =[[NSArray alloc] initWithObjects:UserName,Password,nil];
operationName=[[NSString alloc] init];
operationName =@"ClientLogin";
NSURL *WebServiceUrl=[WebServiceHelper generateWebServiceHTTPGetURL:url : operationName :     Keys:     KeyValue];
NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:WebServiceUrl];
[parser setShouldReportNamespacePrefixes:NO];
[parser setShouldResolveExternalEntities:NO];
[parser setDelegate:self];
[parser parse];
[Keys release];
[KeyValue release];
[WebServiceUrl release];
[NSThread detachNewThreadSelector:@selector(dismissAlertMethod) toTarget:self withObject:nil];
}
@catch (NSException * e)
{
[NSThread detachNewThreadSelector:@selector(dismissAlertMethod) toTarget:self withObject:nil];
}
return Result;
}

-(void)showAlertMethod
{
NSAutoreleasePool *pool1=[[NSAutoreleasePool alloc]init];
progressAlert = [[UIAlertView alloc] initWithTitle:@"Signing in..." message:@"Please wait..."    delegate:nil cancelButtonTitle: nil otherButtonTitles:nil];

CGRect alertFrame = progressAlert.frame;
UIActivityIndicatorView* activityIndicator = [[UIActivityIndicatorView alloc]     initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

activityIndicator.frame = CGRectMake(135,alertFrame.size.height+75, alertFrame.size.width,30);
activityIndicator.hidden = NO;
activityIndicator.contentMode = UIViewContentModeCenter;
[activityIndicator startAnimating];
[progressAlert addSubview:activityIndicator];
[activityIndicator release];
[progressAlert show];
[pool1 release];
}

-(void)dismissAlertMethod
{
NSAutoreleasePool *pool2=[[NSAutoreleasePool alloc]init];
[progressAlert dismissWithClickedButtonIndex:0 animated:YES];
[pool2 release];
}

阅读代码有点困难,但是:您不能从线程执行UI。您的警报必须从主线程创建和显示。

代码有点难读,但是:您不能从线程执行UI。必须从主线程创建并显示警报