2017-04-13 41 views
0

我在我的应用程序中有多个视图控制器。我想知道,有没有办法从第三种观点回到家中,但仍然否定第三种观点?最好没有导航控制器。但请告诉我,如果我需要一个。谢谢您的帮助。解雇家从另一个视图控制器迅速3

+0

为什么你不想要使用导航控制器,它是一种清洁的方式来达到所需的行为。而且,这个问题是很难回答,因为你不” t解释上下文 –

+0

使用展开segue – rMickeyD

回答

0

您需要实现您的自定义Segue,然后将其应用于两个视图之间的Segue。

下面是一个例子(当前观点将取代前一):

class ReplaceSegue: UIStoryboardSegue { 
    override func perform() { 
     let sourceController: UIViewController = self.sourceViewController 
     let destinationController: UIViewController = self.destinationViewController 
     let navigationController = sourceController.navigationController! 
     let controllerStack = NSMutableArray(array: navigationController.viewControllers) 

     controllerStack.replaceObjectAtIndex(controllerStack.indexOfObject(sourceController), withObject:destinationController) 

     navigationController.setViewControllers(controllerStack as NSArray as! [UIViewController], animated: true) 
    } 
} 
0

是这是可能的。在代码中尝试下面的函数。 在您的主视图控制器,输入一种温馨/接收赛格瑞功能:

@IBAction func unwindToVC(segue: UIStoryboardSegue) { 
    if let sourceViewController = segue.source as?  *Name of third view controller* { 
     //in here you can now access any information you 
     //want to retrieve from the third view controller 
     } 
} 

//In your third viewController put the following: 
//make sure you assign cancelSegue to a button or whatever 

func cancelSegue() { 
    performSegue(withIdentifier: "segueToMain", sender: self) 
} 

然后在你提到的第三个视图控制器上的情节串连图板,就在视图控制器的顶部点击从黄色圆圈拖动进入橙色方块“退出”,然后它会弹出一个选项,称为unwindToVC并点击它。确保它被识别(你可以在cancelSegue中看到,我的名字叫做segueToMain)

现在,当你在第三个视图控制器中时,你应该能够按下指定的按钮,它将执行segue

这为我工作,希望它有助于

+0

非常感谢你所有 – c3pNoah

+0

没问题,很高兴它帮助 – PaulBart1

+0

谢谢你paul bartholomew它工作 – c3pNoah

相关问题