iOS 表格视图刷新单元格
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10560202/
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
iOS Table View Refresh Cell
提问by user1120008
I followed the advice in the link below to add images to cells in a table view.
我按照下面链接中的建议将图像添加到表格视图中的单元格中。
Adding Image to Table Cell (iOS)
Is there a way to force refresh a cell i.e. add/remove images or indicators?
有没有办法强制刷新单元格,即添加/删除图像或指示器?
回答by Mike Z
You can call [self.tableview reloadData];
on the tableview and refresh the entire table.
你可以调用[self.tableview reloadData];
的实现代码如下,并刷新整个表。
Otherwise you can do this to refresh a single cell.
否则,您可以执行此操作来刷新单个单元格。
[self.tableView beginUpdates];
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPathOfYourCell] withRowAnimation:UITableViewRowAnimationNone];
[self.tableView endUpdates];
回答by user1139921
Since you already have indexPath of the cell, sometimes this may just do the job
由于您已经拥有单元格的 indexPath,有时这可能只是完成工作
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
[cell reloadInputViews];
回答by Adil Hussain
You can call the reloadRows(at:with:)method of the UITableViewclass to reload certain rows of the UITableViewinstance using a given animation effect.
您可以调用UITableView类的reloadRows(at:with:)方法来使用给定的动画效果重新加载UITableView实例的某些行。
Note that there are similarly named insertRows(at:with:)and deleteRows(at:with:)methods if instead you want to insert or delete certain rows in the UITableViewinstance.
请注意,如果您想在UITableView实例中插入或删除某些行,则有类似命名的insertRows(at:with:)和deleteRows(at:with:)方法。