ios 如何在IOS中动态更新表视图?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7383348/
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
how to dynamically update table view in IOS?
提问by Jeba Prince
i have a table and custom cells created dynamically, i have a http asyn call which gets me JSON data, now i need to update the table cells with the data received...
我有一个动态创建的表格和自定义单元格,我有一个 http 异步调用,它获取我的 JSON 数据,现在我需要用收到的数据更新表格单元格...
回答by Nathanial Woolls
Call:
称呼:
[self.tableView reloadData];
回答by BooleanBoy
Have to NSNotification, one in the loadview and another one in the
必须 NSNotification,一个在加载视图中,另一个在
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
delegate method , like this:
委托方法,像这样:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateTable) name:@"downloadCompleted" object:nil];
The above one in loadview method and the following one in the delegate
上面一个在loadview方法中,下面一个在delegate中
[[NSNotificationCenter defaultCenter] postNotificationName:@"downloadCompleted" object:nil];
the updateTable method will be called once data is obtained from JSON parsing. You can call the reloadData method of the tableview in this method to fill the tableview with obtained values.... Hope this helps.. Cheers...Happy coding..
一旦从 JSON 解析中获得数据,就会调用 updateTable 方法。您可以在此方法中调用 tableview 的 reloadData 方法以使用获取的值填充 tableview....希望这会有所帮助..干杯...快乐编码..
回答by user2168844
call the table reloadData instance method . where ever you want to update the data of table.
调用表 reloadData 实例方法。你想在哪里更新表的数据。
回答by Breedly
Adding a bit more context using swift
.
If you are trying to do this from a class that implements UITableViewController
it will have a property tableView
upon which you can call tableView.reloadData()
.
使用swift
.添加更多上下文。如果您尝试从实现UITableViewController
它的类中执行此操作,则将具有一个属性tableView
,您可以在该属性上调用tableView.reloadData()
.
For example:
例如:
import UIKit
class TableViewController implements UITableViewController {
private func changeData() -> Void {
//... changes data
tableView.reloadData()
}
}
Source: UITableViewController