2011-06-20 3 views
2

は、 は、私がWebサービスからデータを取得、進捗状況、 を表示するには、私 問題がUIIndicatorViewインサイドUIAlertViewを表示します。 進行中に計算された機器の[ホーム]ボタンを押しボタンはその後、私のアプリケーションが近い場合には、 、そして私がアプリケーションを起動しようとすると二度目に(黒い画面が表示されます)アプリケーションが起動しません。 どうすればこの問題を解決できますか?あなたのコードを読むためにのipad-NSThread、エラーチェックの有効なログイン用の

-(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 [email protected]"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]; 
} 

答えて

0

少し難しい、しかし:

私のコードは、あなたがスレッドからUIを行うことはできません。アラートはメインスレッドから作成して表示する必要があります。

関連する問題