Reputation: 191
I have a UITableViewController, which is loading data from a NSURLConnection:
NSURL *url = [NSURL URLWithString:@"http://url.now"];
NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30.0];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error){
if ([data length] > 0 && error == nil){
NSXMLParser *parser = [[NSXMLParser alloc] initWithData:data];
[parser setDelegate:self];
[parser parse];
}
else if (error != nil){
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"No internet connection" message:@"Content." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView performSelectorOnMainThread:@selector(show) withObject:nil waitUntilDone:true];
}
}];
When the parsing ends, the reloaddata method is called. But when the app is loaded, the content of the UITableView is not showing. When I scroll a bit, it get's visible immediately. Reloading is no problem.
How can this be fixed?
Upvotes: 4
Views: 2791
Reputation: 2599
Unchecking "Use Size Classes" option and then coming back and re-checking it again fixes this issue.
Upvotes: 0
Reputation: 191
Solved it. Changed the tableView reloadData to this:
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView reloadData];
});
And it worked like a charm. Thanks for all answers and comments.
Upvotes: 8
Reputation: 1416
What probably happened is that your table loads faster than the time it takes for your commotion to download data. Add a delegate to the class that manage your data and make your table view controller conform to that delegate protocol. Than, once data is downloaded and parsed reload the table.
Upvotes: 0