iOS UITableView的reloadData只刷新表第二次调用我的reload函数 [英] iOS UITableView reloadData only refreshes table the second time I call my reload function

查看:260
本文介绍了iOS UITableView的reloadData只刷新表第二次调用我的reload函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的重新载入功能

- (void) reloadTable:(id)sender
{   
    NSLog(@"Reload Table");
    NSLog(@"%@",[appDelegate queryList]);
    [self.driverTable reloadData];
    [self.driverTable setNeedsLayout];
    [self.driverTable setNeedsDisplay];
}

这里是从webservice接收数据后调用它

Here is where I call it after receiving data from the webservice

if( [elementName isEqualToString:@"Response"]) {
    Response = NO;
    LookupView *lookupView = [[LookupView alloc] initWithNibName:@"LookupView" bundle:nil];
    [lookupView reloadTable:self];
}

问题我现在就是在按搜索按钮并接收数据。该表不使用新数据刷新。如果我再次按下find按钮再次调用相同的函数,表重新加载。现在我知道数据是因为我打印数组,然后我调用表重新加载。

Problem I have right now is after I do a search by pressing a find button and receive the data. The table does not refresh with the new data. If I call the same function again by pressing the find button again the table reloads. Now I know the data is there because I print the array out before I call the table reload.

任何想法为什么?

推荐答案

我遇到了同样的问题。根据苹果的文档,reloadData不应该在插入或删除行的方法中调用。我使用的解决方法是延迟对reloadData的调用,以便它不会立即更新表后。尝试这样:

I have run into the same issue. Per Apple's documentation, reloadData "should not be called in the methods that insert or delete rows." A workaround I have used is to delay the call to reloadData so that it is not immediately after updating table. Try this:

[self performSelector:@selector(delayedReloadData) withObject:nil afterDelay:0.5];

在适当的位置使用以下delayReloadData实施

at the appropriate place with the following implementation of delayReloadData

 -(void)delayedReloadData{
    [self.tableView reloadData];
}

我从这种方法看到的负面影响是,如果表行是可见的,在显示其内容之前有短暂的延迟。

A negative side affect I have see from this approach is that if the table row is visible there is a short delay before it shows its content.

这篇关于iOS UITableView的reloadData只刷新表第二次调用我的reload函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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