【发布时间】:2019-02-02 15:45:10
【问题描述】:
到目前为止,我一直在使用 Objective-C,并决定从现在开始使用 swift 进行开发。
我不知道为什么这个简单的代码不起作用。
我有两个viewControllers作为superview的容器视图,一个叫做'sideViewController',另一个是'dashViewController'。
我有一个从 dashViewController 到另一个名为“nextViewController”的 viewController 的标识符为“Appointment”的segue
如果我尝试在 dashViewController.swift 中执行 egue,它可以正常工作。
但是,如果我尝试在 'sideViewController' 中使用它,为什么它不起作用?
@IBAction public func buttonTapped(_ sender: Any) {
let storyBoard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyBoard.instantiateViewController(withIdentifier: "dashboardViewController")
vc.performSegue(withIdentifier: "Appointment", sender: self) //nothing happens
}
在目标 C 中,我可以将单例用于 dashViewController,如下所示
[[MainViewController sharedViewController] performSegueWithIdentifier:@"Appointment" sender:nil];
但是在swift中,以下代码不起作用
DashboardViewController.sharedInstance.performSegue(withIdentifier: "Appointment", sender: nil)
我已经为此苦苦挣扎了 2 天..
请帮助我。
谢谢
【问题讨论】:
标签: storyboard singleton segue viewcontroller swift4.2