【发布时间】:2018-06-22 20:52:25
【问题描述】:
我有一个应用程序,我通过 Alamofire 接收信息并将其传递到 tableview。我可以进一步获取有关传递给视图控制器的选定产品的更多详细信息。这很好用,但我现在遇到的问题是,当我单击一个单元格以获取有关特定项目的更多详细信息时,它总是必须浏览所有其他项目。如果我单击单元格 5 上的一个项目,详细视图控制器将从项目 1、2、3、4 开始显示,然后是 5,尽管它执行得很快。我相信一旦我关闭模态就像
@IBAction func closeModalPressed(_ sender: Any) {
self.dismiss(animated: true, completion: nil)
}
假设删除了以前的细节。我该怎么做才能让它显示第 5 项而不先循环通过 1-4
选择了行
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let selected = Services.instance.items[indexPath.row]
Services.instance.selected = selected
let index = IndexPath(row: indexPath.row, section: 0)
tableView.reloadRows(at: [index], with: .none)
tableView.selectRow(at: index, animated: false, scrollPosition: .none)
NotificationCenter.default.post(name: NOTIFY, object: nil)
performSegue(withIdentifier: TO_DETAILS, sender: nil)
}
【问题讨论】:
-
你能在 tableview didSelectRow 方法中发布你的代码吗?
-
@nikBhosale 完成
-
你用什么代码告诉细节控制器要显示什么?
-
您实际上是在执行 segue 之前重新加载行我不知道重新加载行的原因是什么,由于这个原因它正在循环遍历以前的单元格