【发布时间】:2019-07-16 21:57:03
【问题描述】:
我有两个 UITableViewControllers,比如说,第一个是 Patient,第二个是 Medicine。单击第一个 UITableView (Patient) 的一个 TableViewCell 将导致显示该选定患者的药物的第二个 UITableView。我在 Storyboard 上定义了我的 Show Segue。
让我描述一下我有时会遇到的问题。我点击一名患者,它不会立即移至医学屏幕。导航不会立即启动。过了一段时间,例如半秒后,我再次点击病人,然后突然有两个 Medicine UITableViewController 向左移动,第一个很快被第二个覆盖。我确信两个 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,
}
【问题讨论】:
-
你需要展示一些来自 vcs 和 storyboard 连接的代码
-
如果不查看代码,我们无法确定发生了什么,但这种延迟响应通常是由于尝试从后台线程更新 UI 造成的。您是否触发表视图更新以响应网络 GET 或异步数据库请求?默认情况下,其中一些完成处理程序/委托方法在后台线程上调用。
-
正如前面两位 cmets 所说,您需要共享一段代码,另一个可能的原因是您从两个代码和链接的单元格上的点击操作触发了您的 segue在情节提要上,这是假设您当然在情节提要中有自己的观点
-
我需要什么代码?准备(为:segue)?
标签: ios swift iphone xcode uitableview