无法更新UITableView

Neo*_*Neo 6 iphone objective-c

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

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];
}
Run Code Online (Sandbox Code Playgroud)

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

我无法使用performSelectorOnMainThread调用上述方法.

Raj*_*Raj 12

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

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

代码示例如下:

- (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];
}
Run Code Online (Sandbox Code Playgroud)