2015-01-13 40 views

回答

1

因此,如果這有助於其他人;我提出了一些類型的代表協議:

protocol JNCommunicationDelegate { 
    func doAction(sender: AnyObject, message: AnyObject) 
} 

,然後加入一個變量來發送該消息的視圖控制器:

var communicationDelegate: JNCommunicationDelegate? 
func setCommunicationDelegate(delegate: JNCommunicationDelegate) { 
    self.communicationDelegate = delegate 
} 

(這樣做的更迅捷的方法是將具有沒有setter ..但是當SEGUE開始在第一控制器這是對我而言只是太多的Java),然後:

override func prepareForSegue(segue: NSStoryboardSegue, sender: AnyObject!) { 
    let destination = segue.destinationController as MyViewControllerController 
    destination.setCommunicationDelegate(self) 
} 

,然後再從第二控制器doAction:方法。

0

否segue定義了從ViewController A到ViewController B的一個轉換。 一個segue在該轉換之後沒有生命期。

您必須手動添加該功能 - 例如,通過委託模式

+0

那麼我會怎麼做呢?我可以添加一個動作來解除視圖控制器在'第一'視圖控制器中的按鈕嗎? – javanut13