我有两个UITableViewController,例如,第一个是Patient,第二个是Medicine。单击第一个UITableView(患者)的一个TableViewCell将导致第二个UITableView,该UITableView显示此所选患者的药物。我在情节提要板上定义了Show Segue。
让我描述一下我有时会遇到的问题。我单击一名患者,它不会立即移至“医学”屏幕。导航不会立即开始。例如,过了半秒钟后,我再次单击患者,然后突然两个左医学UITableViewControllers向左移动,第二个迅速覆盖了第一个。我确定这两个Medicine UITableViewControllers都位于Navagation Controller堆栈上,因为我可以单击左上角的“后退”按钮,然后仍然转到第一个Medicine屏幕。
此问题很少发生,通常是在安装后首次打开应用程序时发生。我已经在模拟器和真实设备上看到了这一点。供您参考,我在第二个屏幕(“药品”屏幕)上检查了位置许可,并询问是否未授予该许可。
那是什么问题?我该如何解决?有与此相关的资源吗?请帮忙。
代码(PatientTVController.swift)
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
super.prepare(for: segue, sender: sender) // call parent
guard segue.source is PatientTVController else {
fatalError("Unexpected source: \(segue.source)")
}
guard let serviceTableViewController = segue.destination as? ServiceTVController else {
fatalError("Unexpected destination: \(segue.destination)")
}
guard let selectedPatientCell = sender as? PatientTableViewCell else {
fatalError("Unexpected sender: \(String(describing: sender))")
}
guard let indexPath = self.tableView.indexPath(for: selectedPatientCell) else {
fatalError("The selected cell is not being displayed")
}
let selectedPatient = patients[indexPath.row]
// set patient id here,
}
答案 0 :(得分:0)
没有很多细节,很难具体指出错误在哪里。如果您可以显示一些代码来清楚地了解导致错误的原因,那将大有帮助。但是,您可以尝试这种方法。
尝试删除当前的序列,然后从PatientTVController而不是UItableView的单元格中设置一个新的序列,如图所示。按住“ Control”键,然后从视图控制器中单击并拖动以创建新的序列。
选择序列,然后导航到属性检查器,然后向序列添加标识符。
使用didSelectRowAt方法,以编程方式执行segue
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
// You can catch the selected patient here and use it later when you need it.
performSegue(withIdentifier: "yourSegueIdentifier", sender: nil)
}