首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >刷新UITableView自定义单元格延迟

刷新UITableView自定义单元格延迟
EN

Stack Overflow用户
提问于 2012-04-10 14:55:27
回答 2查看 681关注 0票数 2

我有一个带有自定义单元格的UITableView,我在解析xml数据后填充(用数组信息服务)。

代码语言:javascript
复制
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    ApplicationCell *cell = (ApplicationCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            [self.cellNib instantiateWithOwner:self options:nil];
            cell = tmpCell;
            self.tmpCell = nil;          
        }       

        infoService *e = [self.infoservices objectAtIndex:indexPath.row];

        cell.name = [e  infoName];

        NSString *infodetails = [e infoDetails];

        if ( infodetails == nil ) {
            cell.details = @"Loading...";
            [self startInfoDownload:e forIndexPath:indexPath];

            NSLog(@"Loading...");
        } else  {
            cell.details = infodetails;
            NSLog(@"Show info detail: %@", infodetails );
        }
        return cell;
}


- (void)infoDidFinishLoading:(NSIndexPath *)indexPath
{
    infoDownloader *infoserv = [imageDownloadsInProgress objectForKey:indexPath];
    if (infoserv != nil)
    {

        [infoservices replaceObjectAtIndex:[indexPath row] withObject:infoserv.appRecord];

        NSIndexPath *a = [NSIndexPath indexPathForRow:indexPath.row inSection:0]; // I wanted to update this cell specifically
        ApplicationCell *cell = (ApplicationCell *)[self.tableView cellForRowAtIndexPath:a];
        cell.details = [[infoservices objectAtIndex:[indexPath row]] infoDetails];

        NSLog(@"Updating=%@", [[infoservices objectAtIndex:[indexPath row]] infoDetails]);
    }
}

对于每个单元格,我使用NSURLConnection sendAsynchronousRequest从对象infoDownloader检索和解析xml数据。

代码语言:javascript
复制
- (void)startDownload

对于每个单独的单元格。

成功解析数据后,将调用来自infoDownloader的委托方法

代码语言:javascript
复制
- (void)infoDidFinishLoading:(NSIndexPath *)indexPath

问题是,虽然

代码语言:javascript
复制
- (void)infoDidFinishLoading:(NSIndexPath *)indexPath 

在分析每个单元格之后被调用,我可以看到

代码语言:javascript
复制
NSLog(@"Updating=%@", [[infoservices objectAtIndex:[indexPath row]] infoDetails]);

在具有正确详细信息的调试器中,单元不会立即刷新,而是在6秒或7秒后刷新。此外,cellForRowAtIndexPath不会从

代码语言:javascript
复制
- (void)infoDidFinishLoading:(NSIndexPath *)indexPath 

由于某种原因,因为在infoDidFinishLoading之后没有调试输出。另外,我不明白cell.details是如何被实际刷新的,因为cellForRowAtIndexPath不会再次被调用。

我试着使用苹果的LazyTableImages加载示例来设置这个功能,我已经成功地使用了它,但我不知道出了什么问题。

EN

Stack Overflow用户

发布于 2013-03-21 17:40:56

任何影响UI的更改都必须在主线程上执行。

正在刷新tableView,通过更改单元格详细信息、重新加载选项卡视图、重新加载行...是否有影响UI的更改。

特别是,您应该使用以下命令在主线程中执行更改:

代码语言:javascript
复制
dispatch_async(dispatch_get_main_queue(), ^{
    cell.details = [[infoservices objectAtIndex:[indexPath row]] infoDetails];
}

或iOS 4之前的版本:

代码语言:javascript
复制
cell performSelectorOnMainThread:@selector(setDetails:) withObject:[[infoservices objectAtIndex:[indexPath row]] infoDetails];
票数 0
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10084373

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档