这在主线程上运行得很好,但由于某些原因,在后台线程上运行时就不起作用了。如果你只是注释掉对dispatch_async的调用,那么这个程序就能正常工作!
代码:
NSString *requestString = [NSString stringWithFormat:@"http://www.songlyrics.com/index.php?section=search&searchW=%@+%@&submit=Search",actualSongName,actualSongArtist];
NSLog(@"0");
TFHpple *requestParser = [TFHpple hppleWithHTMLData:[NSData dataWithContentsOfURL:[NSURL URLWithString:requestString]]];
NSLog(@"1");
NSString *requestedURLXPathQuery = @"//a";
NSArray *requestedStringsNodes = [requestParser searchWithXPathQuery:requestedURLXPathQuery];
NSLog(@"2");下面是记录的内容:
2012-10-11 21:39:05.636 SuperViewer[6612:110b] 0
2012-10-11 21:39:05.651 SuperViewer[6612:907] Unable to parse.
2012-10-11 21:39:06.520 SuperViewer[6612:110b] 1
2012-10-11 21:39:06.565 SuperViewer[6612:110b] 2这都是在后台线程上运行的。此外,我还记录了"requestString“变量和它的罚款。
你知道问题出在哪里吗?Hpple不是在后台线程上运行吗?
谢谢!
发布于 2012-10-12 12:10:23
我不知道你到底有什么问题。但是,不要使用dispatch_async,而要使用NSThread。确保使用
-[NSObject performSelectorOnMainThread:withObject:waitUntilDone:] 在主线程上运行(用于Ui交互功能)
https://stackoverflow.com/questions/12851949
复制相似问题