I’m trying to reload my app with new data from a JSON feed. i’d try;
- (void) Refresh {
[self performSelector:(@selector(refreshDisplay:)) withObject:(_tableView) afterDelay:0.5];
}
and
- (void)refreshDisplay:(UITableView *)tableView {
[_tableView reloadData];
}
Downloading the JSON:
NSString *jsonString = [NSString
stringWithContentsOfURL:[NSURL URLWithString:xmlDataUrl]
encoding:NSUTF8StringEncoding
error:nil];
SBJSON *parser = [[SBJSON alloc] init];
NSDictionary *results = [parser objectWithString:jsonString error:nil];
parser = nil;
[self setTableData:nil];
[self setTableData:[results objectForKey:@"feed"]];
But it’s not reloading my new data from the JSON, does anyone know how i can update the tableview with new data i’m downloading from a online JSON feed? I need to delete the old data from the JSON feed and insert the new data.
Are you sure your data is actually changing? You could place some
NSLogs in your-tableView:cellForRowAtIndexPath:method to make sure it’s getting called. It seems like your issue is that you’re simply telling it to refresh after half a second, and the data may not be loaded by then. I suggest you put the[tableView reloadData]call in the method which actually finishes updating the data, so that you know it’s done by the time you call it.Note too that this method:
isn’t needed. First of all, it ignores the argument and calls
reloadDataon your ivar_tableView. Secondly, if all you wanted to do was reload the data after half a second, you can call:Further, based on the fact that it’s called
_tableViewif you have an@synthesize tableView=_tableViewyou’re better off usingself.tableViewanywhere you can, as this avoids accessing the ivar directly and is considered “good form”.To reiterate, make sure your data source is actually updating the data before calling
reloadDataon the tableview.Edit
To your updated post, simply add
[self.tableView reloadData];at the end of your JSON parsing code.