我想在图像上创建 tableview
(https://www.raizlabs.com/dev/wp-content/uploads/sites/sites/10/1016/05/defeath-default-deselection。gif(在此表视图中,我在返回到具有表观的第一个控制器后看到了选定行的动画。
但是,当我在返回第一个控制器之后,当我在所选行的项目动画中创建默认的tableview
时。如何修复它?
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 10
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: String(format: "Cell%d", indexPath.row), for: indexPath)
return cell
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if (segue.destination is ViewController) {
(segue.destination as? ViewController)?.index = (self.tableView.indexPathForSelectedRow?.row)!
}
}
}
如果要选择后的行颜色在回到后方(屏幕边缘(之后淡出(屏幕边缘(,则可以使用以下方式:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if let indexPath = tableView.indexPathForSelectedRow {
tableView.deselectRow(at: indexPath, animated: true)
}
}