ios 如何在不重新加载完整表格的情况下更新 UITableVIewCell

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14702083/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 22:09:14  来源:igfitidea点击:

How to update a UITableVIewCell without reloading full table

iphoneiosobjective-cuitableview

提问by Newbee

Possible Duplicate:
Is it possible to refresh a single UITableViewCell in a UITableView?

可能的重复:
是否可以在 UITableView 中刷新单个 UITableViewCell?

In a sequence I am updating only a particular object in my list data(NSMUtableArray), once updated its value, To make the GUI update, I was reloaded the full table like below...

在一个序列中,我只更新列表数据(NSMUtableArray)中的一个特定对象,一旦更新了它的值,为了更新 GUI,我重新加载了如下所示的完整表......

[table reloadData];

It worked fine, However in efficiency point, it is hanging little bit while I am scrolling, Is there any way to update only a particular cell without reload full table?

它工作得很好,但是在效率方面,它在我滚动时挂了一点,有没有办法只更新一个特定的单元格而不重新加载完整的表格?

thanks.

谢谢。

回答by amar

 - (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;

Use this

用这个

回答by Scorpian Alive

You can use this..

你可以用这个..

NSArray *indexPathArray = [NSArray arrayWithObject:[NSIndexPath indexPathForRow:1 inSection:0]];
//You can add one or more indexPath in this array...

[tblview reloadRowsAtIndexPaths:indexPathArray withRowAnimation:UITableViewRowAnimationFade];

回答by Rajneesh071

You can reload particular image row using index path .

您可以使用索引路径重新加载特定的图像行。

    [mainTableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
                         withRowAnimation:UITableViewRowAnimationNone];

回答by Nameet

You can get the cell object by -

您可以通过以下方式获取单元格对象 -

UITableViewCell *cell = [table cellForRowAtIndexPath:indexPath];

now change its related values as per your object from data array. It should reflect in the table. Hope this helps.

现在根据数据数组中的对象更改其相关值。它应该反映在表格中。希望这可以帮助。

回答by Rushi

As you are making a GUI update, it's better to use reloadData rather then using any other methods. reloadData is the best way in your case to update the UITableViewas it avoids inconsistency. The other thing which you can do is, you can add a condition in your cellForRowAtIndexPathand let execution happen only for the cell which is modified.

当您进行 GUI 更新时,最好使用 reloadData 而不是使用任何其他方法。reloadData 是您更新数据的最佳方式,UITableView因为它可以避免不一致。您可以做的另一件事是,您可以在您的条件中添加一个条件,cellForRowAtIndexPath并让仅对被修改的单元格执行。

回答by David Chavez

If you're just adding one item, and you wish to have that added to the table, you can manually insert it into your UITableView, here's an example:

如果您只是添加一项,并且希望将其添加到表格中,则可以手动将其插入到 UITableView 中,这是一个示例:

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:_directions.count-1 inSection:0];
NSArray *indexPaths = [NSArray arrayWithObject:indexPath];
[self.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:YES];