1

当我运行我的代码时,我的代码被卡住并给出日志:

void _WebThreadLockFromAnyThread(bool), 0x904db10:从主线程或web线程以外的线程获取web lock。不应从辅助线程调用 UIKit。

这是什么原因,解决方法是什么?

我的代码:

-(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];
    }

       });
    });
}
4

0 回答 0