在swift中隐藏UIViewController(屏幕)

Ami*_*Raj -3 uitabbarcontroller uiviewcontroller segue swift xcode6.3

在此输入图像描述

如您所见,屏幕流程如下:

点击"屏幕A"的"按钮2"后,应用程序会在同一个具有标签栏的故事板中显示"屏幕B".点击"屏幕B"的"红色标签"后,应用程序会显示"绿色按钮"(右上角).点击"屏幕B"的"绿色按钮"后,应用程序会显示"故事板2"的"屏幕C".

点击"屏幕C"的后退按钮后,我需要回到"故事板1"的"屏幕B",无论"屏幕C"出现在哪里,"故事板2"的"屏幕C"应该消失从上到下.

是否有可能这样做,如果是,那么如何?

Riz*_*ikh 7

是的,你可以隐藏UIViewController,因为你UIViewController只是正常UIView.

所以只需创建一个@IBOutletfor your UIView和use .hidden方法,如下所示:

 @IBOutlet weak var mainview: UIView!
 override func viewDidLoad() {
    super.viewDidLoad()

   mainview.hidden = true
}
Run Code Online (Sandbox Code Playgroud)

编辑:
正确指定要实现的目标.如果您的显示viewController来自屏幕A或B,直到应该存在某些条件或者ViewController需要一些输入值(字符串,整数等)来处理它并不重要.

Edit2:
参考这个答案如何检查使用了哪个segue

编辑3:
根据你的编辑答案(移动到ScreenC到ScreenB,无论screenC是来自ScreenA还是ScreenB),最好使用三个独立的3个故事板并根据需要调用目标ViewController.

这是ViewController类的代码(移动ScreenA - > ScreenBScreenA - > ScreenC)

@IBAction func buttonAisClick(sender: AnyObject) {
// move to ScreenC directly
    var moveToNextVC:ViewController3 = self.storyboard?.instantiateViewControllerWithIdentifier("ViewController3") as! ViewController3

    self.presentViewController(moveToNextVC, animated: true, completion: nil)
}


@IBAction func ButtomBisClick(sender: AnyObject) {
// move to ScreenB
    var moveToNextVC:ViewController2 = self.storyboard?.instantiateViewControllerWithIdentifier("ViewController2") as! ViewController2

    self.presentViewController(moveToNextVC, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)

ViewController2类的代码(从ScreenB - > ScreenC移动)

@IBAction func ScreenBbuttonIsClick(sender: AnyObject) {
// move to ScreenC
    var moveToNextVC:ViewController3 = self.storyboard?.instantiateViewControllerWithIdentifier("ViewController3") as! ViewController3

    self.presentViewController(moveToNextVC, animated: true, completion: nil)

}
Run Code Online (Sandbox Code Playgroud)

ViewController3类的代码(从ScreenC - > ScreenB移动)

@IBAction func ScreenCbuttonIsclick(sender: AnyObject) {
    var moveToNextVC:ViewController2 = self.storyboard?.instantiateViewControllerWithIdentifier("ViewController2") as! ViewController2

    self.presentViewController(moveToNextVC, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)