OK I'm hoping I'm missing something basic here - I am not very expert at this. It should be self-explanatory without example code: I parse a web-hosted xml file consisting of a list of titles to be displayed in a tableView and associated URLs to pass to a webView when a cell is selected. The parsing happens in the tableView into a dictionary. If I parse on the main thread it works nicely but I'm worried about hanging the UI if the signal is poor. So I wrap the parsing call in a dispatch queue as per examples on here and now it presents an empty table. But if I go back up the view hierarchy and try again (it's embedded in a navigation controller) then it works, there is my table fully populated. I'm assuming that by using a secondary thread somehow the table is created before the content array is populated. How do I get round this? Thanks! Andrew
Implement the - (void)parserDidEndDocument:(NSXMLParser *)parser
delegate method of NSXMLParser
. And call reloadData
of your tableView from that method.
- (void)parserDidEndDocument:(NSXMLParser *)parser
{
dispatch_sync(dispatch_get_main_queue(), ^{
[yourTable reloadData];
});
}
Refer NSXMLParserDelegate