I am trying to update a list of cells UITableView every time an element is finished being parsed in an XML file.
I attempt to do so by running the following code in my UITableViewController:
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if ([elementName isEqualToString:@"item"]) {
[self.tableView reloadData];
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
if (!([string isEqualToString:@"\n "] || [string isEqualToString:@"\n"])) {
[_idArray addObject:string];
}
}
Using breakpoints I can see that the line [self.tableview reloadData]
is being called after every element finishes. However, the tableview does not update with the proper text.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
// Configure the cell...
if (_idArray.count > 0) {
[cell.detailTextLabel setText:[_idArray objectAtIndex:indexPath.row]];
}
return cell;
}
I am setting the numberofrowsinsection
to _idArray.count
and the numberofsectionsintableview
to 1
The TableView is set properly to be the delegate and datasource in this file
if I add a sleep(1)
after each reloadData
it waits one second and NSLog
s properly, but does not reload the actual table.
When the entire file is done parsing, they all suddenly appear properly.
How do I have them appear incrementally in the right way?