开发者

Invoking a UIPopoverViewController on Main Thread from Secondary Thread

I am doing my functionality in a secondary thread and once I get the result, I call the function that pops my ViewController in the main thread. But I get the following error:

void WebThreadLockFromAnyThread(), 0x5c6dec0: Obtaining the web lock from a thread other than the main thread or the web thread. UIKit should not be called from a secondary thread..

I am using the code below:

-(IBAction)done{    
  if([self validateRegistrationDetails]){
    [NSThread detachNewThreadSelector:@selector(invokeWebService) toTarget:self withObject:nil];
  }
}

-(void) invokeWebService{
  NSAutoreleasePool *pool=[[NSAutoreleasePool alloc]init];
  NSString *url = [NSString stringWithFormat:@"%@%@action=1&userName=%@&eMail=%@&firstName=%@&lastName=%@&mobileNo=%@",kBaseURL,kRegisterFunction,userName.text,eMail.text,firstName.text,lastName.text,mobileNo.text]; 
  [ADCUtilities performSelectorOnMainThread:@selector(updateText:) withObject:@"Registering... "waitUntilDone:NO];
  [ADCUtilities performSelectorOnMainThread:@selector(showIndicator:) withObject:self.view waitUntilDone:NO];
  NSDictionary *tempDict = [webService makeAPICall:url];
  [NSThread sleepForTimeInterval:3];
  if(tempDict!=nil){
    NSString *tempLoginSuccess = [tempDict valueForKey:kLoginStatus] ;
    if([tempLoginSuccess isEqual:@"LoginSuccess"]){
      [ADCUtilities displayAlertView:NSLocalizedString(@"REG_SUCCESS",@"")];
      [self performSelectorOnMainThread:@selector(开发者_如何转开发popViewController) withObject:nil waitUntilDone:NO];
    } else {
      [ADCUtilities performSelectorOnMainThread:@selector( dismissIndicator) withObject:nil waitUntilDone:NO];
      [ADCUtilities displayAlertView:NSLocalizedString(@"REG_FAILED",@"")];
    }
   } else {
      [ADCUtilities performSelectorOnMainThread:@selector( dismissIndicator) withObject:nil waitUntilDone:NO];
      [ADCUtilities displayAlertView:NSLocalizedString(@"REG_FAILED",@"")];     
   }
   [pool release];  
}

-(void)popViewController{       
  [self.navigationController popViewControllerAnimated:YES];    
}


I think your problem is actually [ADCUtilities displayAlertView:NSLocalizedString(@"REG_SUCCESS",@"")], which I assume displays some sort of UIAlertView. You should never access any UIKit classes except from the main thread.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜