UITableView 没有第一次显示,只有在滚动一点时 [英] UITableView not showing first time, only when scrolling a bit

查看:28
本文介绍了UITableView 没有第一次显示,只有在滚动一点时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 UITableViewController,它从 NSURLConnection 加载数据:

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];
    }
}];

解析结束时调用reloaddata方法.但是当应用加载时,UITableView 的内容没有显示.当我滚动一下时,它会立即可见.重新加载没问题.

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.

如何解决这个问题?

推荐答案

解决了.将 tableView reloadData 更改为:

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.

这篇关于UITableView 没有第一次显示,只有在滚动一点时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆