无法更新UITableView [英] Unable to update UITableView

查看:84
本文介绍了无法更新UITableView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有UITableViewController作为RootViewController。我需要向表中添加行,具体取决于我从RootViewController的线程启动的另一个线程获取的数据。当我从其他线程返回到我的RootViewController的线程时,我有更新的数据,但我无法更新TableView。我调用了 [self.tableview reloadData]; 方法,但这似乎不起作用。我也尝试过 [self.tableview setNeedsDisplay] ,但没有成功。如何使用新数据更新TableView?

I have UITableViewController as the RootViewController. I need to add rows to the table depending on data I get from another thread which I initiate from the RootViewController's thread. When I retun back from other thread to my RootViewController's thread I have the updated data, But I can't update the TableView. I called the [self.tableview reloadData]; method but that doesnt seem to work. I also tried the [self.tableview setNeedsDisplay] call but with no success. How do I update the TableView with new data?

In my RootViewController Class I have:

- (void) reload {

for(int i=0;i<[camDetails count];i++)
 {
    cCameraInformation *obj = [[cCameraInformation alloc] init];
    obj = [camDetails objectAtIndex:i];
    NSString *tString = [[NSString alloc] initWithFormat: @"        Remote     %s     %s",[obj->sCameraid UTF8String],[obj->sCameraid UTF8String]];
    [tableEntry addObject:tString];
 }
 [self.tableView reloadData];
}

然后有一个接收类线程不断接收数据。它的基类是NSObject。所以,我使用了Application委托类(它有一个RootViewController类的实例)在我的接收线程中调用RootViewController类的重载数据方法。

Then there is a receive class thread which is continuously receiving data. Its base class is NSObject. So, I used the Application delegate class ( which has an instance of RootViewController class ) to call this reload data method of the RootViewController class in my receive thread.

我无法使用performSelectorOnMainThread来调用上面的方法。

I am unable to invoke the above method using performSelectorOnMainThread.

推荐答案

嘿,你确定要更新主视图上的表视图显示/重新加载tableview线?我面临同样的问题,数据在那里,但直到用户滚动,tableview没有更新

hey are you sure you are updating the table view display / reloading tableview on the main thread? i faced the same problem, the data was in there but until user scrolls, tableview was not updated

谷歌搜索后我知道你需要调用reloadData方法主要的ui线程

upon googling i came to know you need to call the reloadData method on the main ui thread

下面的代码示例:

- (void) getDataOnNewThread
{
    // code here to populate your data source
    // call refreshTableViewOnMainThread like below:
    [self performSelectorOnMainThread:@selector(refreshTableView) withObject:nil waitUntilDone:NO];
}

- (void) refreshTableView
{
    [tableView reloadData];
}

这篇关于无法更新UITableView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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