我有一个父视图(with ViewController)
,其中有一个侧边栏菜单,其中包含containerView(ContainerViewController)
。在containerView
,我有2 segue
链接他们自己的视图和viewController(Screen1与Screen1ViewController,Screen2与Screen2ViewController)。
我有按钮可以从screen1
启动screen2
和ViewController
,但设置performSegue()
功能似乎不会触发。
的ViewController
import UIKit
class ViewController: UIViewController {
var container : ContainerViewController!
@IBOutlet var SideBar: UIView!
@IBOutlet weak var viewConstraint: NSLayoutConstraint!
override func viewDidLoad() {
super.viewDidLoad()
container = self.storyboard?.instantiateViewController(withIdentifier: "ContainerViewController") as! ContainerViewController
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
if segue.identifier == "tocontainer"{
self.container = segue.destination as! ContainerViewController
}
}
@IBAction func launchScreen1(_ sender: Any) {
container.performSegue(withIdentifier: "toscreen1", sender: self)
}
@IBAction func launchScreen2(_ sender: Any) {
container.performSegue(withIdentifier: "toscreen1", sender: nil)
}
}
ContainerViewController
import UIKit
class ContainerViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
func launchScreen2() {
print("launchscreen2")
self.performSegue(withIdentifier: "toscreen1", sender: self)
}
}
正如您所看到的,我甚至尝试使用函数launchScreen2
来调用按钮。 print
消息确实出现在控制台中,但不会对self.performSegue
产生任何影响。
我相信我准备错误的方式是错误的,我只是不知道还有什么可以尝试。