我想将tableview单元格的indexPath.row从一个viewController转换为另一个viewController。
var index = 0
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
index = indexPath.row
performSegue(withIdentifier: "cellIndex", sender: self)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.destination is trackSavingViewController{
let TSController = segue.destination as! trackSavingViewController
TSController.indexCell = index
}
}
但所有剂量只是传递原始值(index = 0),而不是所选行的值。我该怎么做来修复代码?
答案 0 :(得分:0)
准备(for segue)
let cell = sender as! UITableViewCell
let indexPath = tableView.indexPath(for: cell)
TSController.indexCell = indexPath.row
答案 1 :(得分:0)
func tableView(_ tableView:UITableView,didSelectRowAt indexPath:IndexPath){ 让storyboard = UIStoryboard(名称:" Main",bundle:nil) 让Dvc = storyboard.instantiateViewController(withIdentifier:" DataVC")为! DataVC
Dvc.getRollNo = arrayStudent[indexPath.row].strRollNo
Dvc.getName = arrayStudent[indexPath.row].strName
self.navigationController?.pushViewController(Dvc, animated: true)
}