我正在尝试导航到特定的viewController。我在两个viewControllers中都有相同的tableView插座,一个是主VC,第二个是requestHistory VC。例如,如果用户在第一个viewController上并在tableview中选择单元格,它应该导航到特定的viewController,如果用户在第二个VC上并且选择了它应该重定向到另一个VC的相同单元格,则应该导航到第二个VC。请注意,我使用相同的表格视图单元格出口的VC和所需的结果是每个VC故事板应重定向到他们的特定目的地。我不确定我正面临的错误如下 这是我目前的代码:
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print("Row \(indexPath.row) selected")
var currentStoryboard = UIStoryboard(name: "DoctorHomeViewController", bundle: nil)
if currentStoryboard == "DoctorHomeViewController" {
let storyboardd = UIStoryboard(name: "DoctorHome", bundle: Bundle.main)
let eventViewController = storyboardd.instantiateViewController(withIdentifier: "EventDetailsNav") as? UIViewController
self.navigationController?.pushViewController(eventViewController!, animated: true)
}
else{
let storyboardd = UIStoryboard(name: "DoctorHome", bundle: Bundle.main)
let eventViewController = storyboardd.instantiateViewController(withIdentifier: "RequestsHistory") as? UIViewController
self.navigationController?.pushViewController(eventViewController!, animated: true)
}
}
}
任何帮助都会非常明显。
答案 0 :(得分:0)
首先,您需要在身份检查器中为故事板中的相应视图控制器标记“使用故事板ID”,然后获取故事板ID并将其与您的View控制器进行比较。
let currentStoryboard : String! = self.restorationIdentifier
if currentStoryboard == "DoctorHomeViewController" {
let storyboard = UIStoryboard(name: "DoctorHome", bundle: Bundle.main)
let eventViewController = storyboard.instantiateViewController(withIdentifier: "EventDetailsNav") as! EventDetailsNav
self.navigationController?.pushViewController(eventViewController!, animated: true)
}
else{
let storyboard = UIStoryboard(name: "DoctorHome", bundle: Bundle.main)
let eventViewController = storyboard.instantiateViewController(withIdentifier: "RequestsHistory") as RequestsHistory
self.navigationController?.pushViewController(eventViewController!, animated: true)
}
希望这会对你有所帮助。