UITableView is not displayed for the first time, only when scrolling

I have a UITableViewController that loads data from 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 application is loaded, the contents of the UITableView are not displayed. When I scroll a little, it becomes visible right away. Rebooting is not a problem.

How can this be fixed?

+4
source share
3 answers

I decided. Changed tableView reloadData file:

 dispatch_async(dispatch_get_main_queue(), ^{
        [self.tableView reloadData];
 });

And it worked like a charm. Thanks for all the answers and comments.

+9
source

, , , , , , . , , . , , .

0

" ", , .

  • xib.
  • Interface Builder.
  • "" > "" > " ".
  • " " " ".
  • . "Use Size Classes".
0
source

All Articles