如何重新加载UITableView,而不停止单元格选择动画 [英] How to reload UITableView without stopping cell selection animation

查看:131
本文介绍了如何重新加载UITableView,而不停止单元格选择动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户点击一个单元格时,我想更新我的 UITableView ;包括该抽头单元的内容。最简单的方法是更新内部参数,然后调用 [self.tableView reloadData];

When the users taps on a cell, I want to update my UITableView; including the contents of this tapped cell. Easiest way is to update internal parameters and then invoke [self.tableView reloadData];.

c $ c> reloadData 会立即停止我轻按的单元格的nice blue-> none选择动画。

However, reloadData immediately stops the nice blue->none selection animation of my tapped cell.

更新我的表格单元格,而不停止已轻敲的单元格的动画?

Is there a (standard) way to update my table cells without stopping the tapped cell's animation?

注意,在这种情况下,我不添加或删除单元格;我只想更改内容(例如,启动活动指示器或更改标签的颜色。)

Note in this case I don't add or delete cells; I just want to contents to change (e.g. start an activity indicator, or change the color of labels.)

推荐答案

你可以得到指向所有可见单元格的指针并更新它们。这样的东西:

In your case you can just get pointers to all visible cells and update them. Something like this:

- (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath
{
    NSArray* visibleCells = [tableView indexPathsForVisibleRows];

    for (NSIndexPath* indexPath in visibleCells)
    {
        UITableViewCell* cell = [self.tableView cellForRowAtIndexPath:indexPath];

        [self updateCell:cell atIndexPath:indexPath]; // Your method, which updates content...
    }
}

如果你想更新其他单元格的内容,你可以使用像这样:

And if you want to update other cells content you can use something like this:

- (void)tableView:(UITableView*)tableView willDisplayCell:(UITableViewCell*)cell forRowAtIndexPath:(NSIndexPath*)indexPath
{
    [self updateCell:cell atIndexPath:indexPath]; // Your method, which updates content...
}

显示正确的内容。

关于创建内容:

- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString* CellIdentifier = @"Cell";
    UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

        [self createContentForCell:cell atIndexPath:indexPath]; // so here to create content or customize cell
    }

    return cell;
}

这篇关于如何重新加载UITableView,而不停止单元格选择动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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