0
如何在控制檯中捕獲NSXMLParser的錯誤?NSXMLParser未顯示錯誤日誌
我的項目正在使用官方的「LazyTableImages」。
問題是它不是一直在工作,表沒有得到任何價值。
這裏是香港專業教育學院做得到一些調試信息:
配售 「的CachePolicy:0和timeoutInterval:160.0」,以避免網址超時:
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:TopPaidAppsFeed] cachePolicy:0 timeoutInterval:160.0]
然後添加 「的NSLog(@」 的數據: %@「字符串)」來檢查,如果我有XML當期的:
NSXMLParser *parser = [[NSXMLParser alloc] initWithData:self.dataToParse];
NSString *string = [[NSString alloc] initWithData:self.dataToParse encoding:NSUTF8StringEncoding];
NSLog(@"data: %@", string);
[parser setDelegate:self];
[parser parse];
控制檯顯示這些在XML開始和任何別的東西是好的就可以了:
2014-02-24 11:54:30.566 MyXMlParserTest[1419:1403] data: <?xml version="1.0" encoding="UTF-8"?>
後,我把這個parseError檢查錯誤,但沒有happend:
- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError
{
NSString * errorString = [NSString stringWithFormat:@"Unable to download data (Error code %i)",[parseError code]];
UIAlertView * errorAlert = [[UIAlertView alloc] initWithTitle:@"Error loading content" message:errorString
delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[errorAlert show];
}
然後我把 「的NSLog(@」 nodeCount)」上connectionDidFinishLoading:
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
self.appListFeedConnection = nil; // release our connection
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
// create the queue to run our ParseOperation
self.queue = [[NSOperationQueue alloc] init];
// create an ParseOperation (NSOperation subclass) to parse the RSS feed data
// so that the UI is not blocked
ParseOperation *parser = [[ParseOperation alloc] initWithData:self.appListData];
parser.errorHandler = ^(NSError *parseError) {
dispatch_async(dispatch_get_main_queue(), ^{
[self handleError:parseError];
});
};
// Referencing parser from within its completionBlock would create a retain
// cycle.
__weak ParseOperation *weakParser = parser;
parser.completionBlock = ^(void) {
if (weakParser.appRecordList) {
// The completion block may execute on any thread. Because operations
// involving the UI are about to be performed, make sure they execute
// on the main thread.
dispatch_async(dispatch_get_main_queue(), ^{
// The root rootViewController is the only child of the navigation
// controller, which is the window's rootViewController.
RootViewController *rootViewController = (RootViewController*)[(UINavigationController*)self.window.rootViewController topViewController];
rootViewController.entries = weakParser.appRecordList;
NSUInteger nodeCount = [rootViewController.entries count];
NSLog(@"nodeCount: %lu", (unsigned long)nodeCount);
// tell our table view to reload its data, now that parsing has completed
[rootViewController.tableView reloadData];
});
}
// we are finished with the queue and our ParseOperation
self.queue = nil;
};
[self.queue addOperation:parser]; // this will start the "ParseOperation"
// ownership of appListData has been transferred to the parse operation
// and should no longer be referenced in this thread
self.appListData = nil;
}
和它返回:
014-02-24 11:54:30.582 MyXMlParserTest[1419:a0b] nodeCount: 0
從這一點我不在哪裏檢查。 我在真實和模擬器設備上都嘗試了這一點,併發生了相同的結果。 其中10個工作時間和表格填滿。另外9次沒有任何事情發生。 xml的字符串標記始終是相同的。只有圖片url標籤正在改變。