iphone - 在没有重新加载数据的情况下强制在表中进行屏幕更新

标签 iphone ios uitableview reloaddata

我将自定义颜色放入可根据情况改变的表格单元格中。下面的代码可以很好地来回改变颜色。我不喜欢每次都必须执行 reloadData 才能显示颜色的事实。是否有更便宜的方法来强制更新单元格颜色?

这里还有其他代码被剥离了。

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // testing for old selected color
    if (checkedIndexPath)
    {
        // returning old checked cell back to blue
        UITableViewCell *uncheckCell = [tableView cellForRowAtIndexPath:checkedIndexPath];
        uncheckCell.backgroundColor = [UIColor blueColor];
    }

    // changing selected cell background color
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    cell.backgroundColor = [UIColor greenColor];
    checkedIndexPath = indexPath;

    // reloadingtable data
    [self.tableVerseView reloadData];
}

最佳答案

您不需要 reloadData 方法。有 reloadRowsAtIndexPaths 方法:

- (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [(MyCellClass *)[self.tableView cellForRowAtIndexPath:indexPath] setBackgroundColor:[UIColor greenColor]];
    [self.tableView reloadRowsAtIndexPaths:[self.tableView indexPathsForVisibleRows]  withRowAnimation:UITableViewRowAnimationAutomatic];
}

关于iphone - 在没有重新加载数据的情况下强制在表中进行屏幕更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15175961/

相关文章:

iphone - 将UIView中的UIImageView对象添加到NSMutableArray中

iphone - iPhone 上 UISlider 的弹性效果

ios - 创建 App ID,Bundle Identifier

c# - iOS TableView 按钮被多次调用

iphone - 你如何处理在 iOS 中获取数据的单独线程?

iphone - 如何在 iPad 中显示和隐藏所选表格行索引的 View ?

ios - 您可以动态分配 CFBundleDocumentTypes(使用私有(private) API 吗?)

ios - dispatch_async 是否复制内部 block

ios - Swift 数组未附加到

ios - 目标 - C - UITableView cellForRowAtIndexPath 从未调用过