[英]How to perform a segue from a pushed vc that has the segue defined in the storyboard
Here is the thing: my storyboard as a SettingViewController (after named SVC) and a StationsViewcontroller from which the latter is wired to a details view controller by the "openDetails" segue. 事情是这样的:我的情节提要板是SettingViewController(以SVC命名)和StationsViewcontroller,后者通过“ openDetails” segue连接到Details View Controller。
For practical reasons, my SVC can push several levels of specifics settings view controllers, which I did not defined in the storyboard. 出于实际原因,我的SVC可以推送多个级别的详细信息设置视图控制器,这在情节提要中没有定义。
At one point, one of those vc pushes the StationsViewController, which then can issue a performSegue to the detail: unfortunately, I get the "openDetails" segue is not defined. 某一时刻,其中一个vc推送了StationsViewController,然后可以对详细信息发出performSegue:不幸的是,我得到的“ openDetails” segue没有定义。
What should I do to fix the issue? 我应该怎么做才能解决这个问题?
-- -
The code has nothing peculiar, in the SettingsViewController, I push others VC, including the StationsViewController: 代码没有什么特别的,在SettingsViewController中,我推送了其他VC,包括StationsViewController:
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
// Gracefully remove the selection
tableView.deselectRow(at: indexPath, animated: true)
guard let section = MainSections(rawValue: indexPath.section) else { return }
switch section {
case .stations:
let vc = StationsViewController()
// Do no segue at dismiss
vc.onlyDismiss = true
vc.didDismiss = {
self.navigationController?.popViewController(animated: true)
}
push(vc, hideNavigation: true)
// Blah blah
And in the StationsViewController where I want to get to the details vc, I perform the segue: 在要获取详细信息vc的StationsViewController中,执行以下命令:
func openPoiDetails(_ gs: GasStation) {
poiDetails = gs
performSegue(withIdentifier: "poiDetails", sender: nil)
// Blah blah
The storyboard is as follows, and we can see the StationsViewController on the left is wired to the details vc via the "openDetails" segue: 故事板如下,我们可以看到左侧的StationsViewController通过“ openDetails” segue连接到了明细vc:
The problem is that your StationsViewController
was just created from its initializer and the storyboard
knows nothing about it. 问题是您的
StationsViewController
只是从其初始化程序创建的, storyboard
提要对此一无所知。 Therefore, you can't use the segue. 因此,您不能使用segue。 Instead, you need to ask the
storyboard
to instantiate the StationsViewController
: 相反,您需要让
storyboard
实例化StationsViewController
:
Replace: 更换:
let vc = StationsViewController()
with: 与:
let vc = self.storyboard?.instantiateViewController(withIdentifier: "StationsViewController") as! StationsViewController
Make sure you set the "StationsViewController"
as the Storyboard ID in the Identify Inspector in Xcode. 确保在Xcode的“ 识别检查器
"StationsViewController"
中将"StationsViewController"
设置为Storyboard ID 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.