我一直在尝试在另一个 View Controller 完成保存文件并展开到 TableView 后重新加载数据
顺便说一句,因为这个 TableView 是在 UIViewController
上创建的,所以我在尝试放置 tableview.reload()
线程 1:EXC_BAD_ACCESS(代码=2,地址=0x7ffedffbcfa8)
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
tableView.reloadData()
return fileURLs.count
}
我猜这样做可能会导致无限循环并永远保留 reloadData?
实现这个方法的正确方法是什么?
编辑
放
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(true)
tableView.reloadData()
}
或
@IBAction func unwindToCSVList(sender: UIStoryboardSegue) {
//tableView.reloadData()
}
无论哪种方式都不起作用,这是否与我的 UITableView
委托(delegate)有关?
最佳答案
tableView.reloadData()
导致对 numberOfRowsInSection
的调用,反之亦然。您猜对了:无限循环。
您可以执行以下操作:
- 创建一个委托(delegate),它将由第一个 Controller 执行。
- 第二个 Controller 将调用委托(delegate)方法并重新加载其中的表。
委托(delegate)示例:get indexPath of UITableViewCell on click of Button from Cell
或者简单的方法。
在 ViewWillAppear
或 viewDidAppear
方法中调用 tableView.reloadData()
。
关于ios - 在另一个 View Controller 展开 segue 后重新加载 UIView 数据上的自定义 TableView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47150465/