iOS 11.3 - 来自parentViewController的ContainerViewController中的performSegue

时间:2018-04-06 04:39:50

标签: ios swift

我有一个父视图(with ViewController),其中有一个侧边栏菜单,其中包含containerView(ContainerViewController)。在containerView,我有2 segue链接他们自己的视图和viewController(Screen1与Screen1ViewController,Screen2与Screen2ViewController)。 enter image description here

我有按钮可以从screen1启动screen2ViewController,但设置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产生任何影响。

我相信我准备错误的方式是错误的,我只是不知道还有什么可以尝试。

0 个答案:

没有答案