[英]Custom segue not working in iOS 9.1
我正在嘗試創建自定義序列。 第一次不起作用。 之后,我通過創建一個擴展UIStoryboardSegue的新文件並創建一個稱為“ perform”的方法找到了解決方案。 現在就可以使用,而無需在ViewController中使用prepareSegue。 我將以前的代碼從prepareSegue復制到新的UIStoryboardSegue文件中的“ Perform”函數中。 它打印出消息,但委托不起作用。
查看控制器
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
自定義Segue
class CustomSegue: UIStoryboardSegue {
let transitionManager = TransitionManager()
override func perform() {
NSLog("Perform");
let toViewController = self.destinationViewController as UIViewController
toViewController.transitioningDelegate = self.transitionManager
}
}
我在Transition Manager的每個函數中都設置了斷點,但它們都沒有執行和停止。
Segue設置:
問題: TransitioningDelegate無法正常工作
完整的源代碼: 此處
問題是您的perform
實施不做任何事情:
override func perform() {
let toViewController = self.destinationViewController as UIViewController
toViewController.transitioningDelegate = self.transitionManager
}
您要做的只是創建一個視圖控制器,為它提供過渡委托,然后將其丟棄。 您不執行任何過渡! 但是,這恰恰是安全的工作。 目前尚不清楚您可能期望發生什么。
如果這個想法是,這應該是一個存在(模式)SEGUE,那么你應該讓一個存在(模式)賽格瑞的故事板,指定您的自定義SEGUE類,然后,在你的perform
實現,調用super
做實際演示:
override func perform() {
let toViewController = self.destinationViewController as UIViewController
toViewController.transitioningDelegate = self.transitionManager
super.perform() // this will work, _if_ you have specified a present (modal) segue
}
或者,您的perform
可以通過以目標視圖控制器為參數在源視圖控制器上調用presentViewController:...
來執行演示。
但是你的 perform
什么也沒做。 一無所有。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.