Iphone 未知警报无效\u WebThreadLockFromAnyThread(bool),
当我运行我的代码时,我的代码被卡住,并以以下方式给出日志: void\u WebThreadLockFromAnyThread(bool),0x904db10:从主线程或web线程以外的线程获取web锁。不应从次线程调用UIKit 原因是什么,解决办法是什么 我的代码:Iphone 未知警报无效\u WebThreadLockFromAnyThread(bool),,iphone,ios,ipad,Iphone,Ios,Ipad,当我运行我的代码时,我的代码被卡住,并以以下方式给出日志: void\u WebThreadLockFromAnyThread(bool),0x904db10:从主线程或web线程以外的线程获取web锁。不应从次线程调用UIKit 原因是什么,解决办法是什么 我的代码: -(IBAction)action:(id)sender{ NSLog(@"HI"); [self performSelectorInBackground:@selector(parse) withObject:
-(IBAction)action:(id)sender{
NSLog(@"HI");
[self performSelectorInBackground:@selector(parse) withObject:nil];
}
-(void)parse{
rssOutputData = [[NSMutableArray alloc]init];
//[self performSelectorOnMainThread:@selector() withObject:nil waitUntilDone:NO];
[NSThread detachNewThreadSelector: @selector(startIndicator) toTarget: self withObject: self];
url=[[NSURL alloc]initWithString:[NSString stringWithFormat:@"http://service.technologyorg.com/service1/AuthenticateStudent=%@,%@,1",t1.text,t2.text]];
NSLog(@"A%@",url);
NSURLRequest *lRequest = [NSURLRequest requestWithURL:url
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:30.0];
NSURLResponse *response;
NSError * error;
//[NSURLConnection connectionWithRequest:lRequest delegate:self];
[NSURLConnection sendSynchronousRequest:lRequest returningResponse:&response error:&error];
NSLog(@"AB%@",response);
if (nil == response) {
NSLog(@"%@",error);
[self performSelectorOnMainThread:@selector(updateTable) withObject:nil waitUntilDone:NO];
UIAlertView * alert=[[UIAlertView alloc]initWithTitle:@"Connection failed!" message:nil delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
}
xmlData=[[NSMutableData alloc]initWithContentsOfURL:url];
NSLog(@"B%@",xmlData);
xmltitle=nil;
xmlParserObject =[[NSXMLParser alloc]initWithData:xmlData];
[xmlParserObject setDelegate:self];
dispatch_async(dispatch_get_global_queue(0, 0), ^{
[xmlParserObject parse];
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"XML:%@",xmllink);
if ([xmltitle isEqualToString:@"true"]) {
HomeViewController *lv=[[HomeViewController alloc]init];
lv.s1=[[NSString alloc]initWithFormat:@"%@",xmllink];
lv.s2=[[NSString alloc]initWithFormat:@"%@",xm1];
myStaticPassword=[[NSString alloc]initWithFormat:@"%@",xm2];
[self presentModalViewController:lv animated: YES];
[self performSelectorOnMainThread:@selector(updateTable) withObject:nil waitUntilDone:NO];
}else{
[self performSelectorOnMainThread:@selector(updateTable) withObject:nil waitUntilDone:NO];
UIAlertView * alert=[[UIAlertView alloc]initWithTitle:@"Incorrect Username/Password" message:@"Please check your Username or Password" delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:nil, nil];
[alert show];
}
});
});
}
原因:您正在从后台线程调用UIKit。解决方案:不要这样做。请仔细检查我的代码和我遗漏的地方。你正在创建IDK。有多少后台线程,你在视图控制器和其他UI上操作。你应该只在主线程上这样做。检查我的答案并在主线程上显示你的警告视图。。。