我在辅助线程中执行我的功能,一旦得到结果,我调用在主线程中弹出我的ViewController的函数。但是我收到以下错误:
void WebThreadLockFromAnyThread(),0x5c6dec0:从主线程或Web线程以外的线程获取Web锁定。不应该从辅助线程调用UIKit。。
我正在使用以下代码:
-(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];
}
答案 0 :(得分:3)
我认为您的问题实际上是[ADCUtilities displayAlertView:NSLocalizedString(@"REG_SUCCESS",@"")]
,我假设它显示某种UIAlertView
。除了主线程之外,你永远不应该访问任何UIKit类。