2017-04-13 80 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

相關問題