2016-12-31 78 views
0
class CustomSegue: UIStoryboardSegue { 

    override init(identifier: String?, source: UIViewController, destination: UIViewController) { 
     super.init(identifier: identifier, source: source, destination: destination) 
    } 

    override func perform() { 

     self.source.navigationController?.pushViewController(self.destination, animated: true) 

    } 

} 

在上面的代碼中,我重寫了segue的行爲。 它應該使用pushViewController只有當這種類型是顯示(例如:推)對於其他類型它應該執行它可以默認的行爲。UIStoryboardSegue子類識別種類

如何在子類perform()方法中找到segue的Kind

 override func perform() { 

      if kind==Push { 
       self.source.navigationController?.pushViewController(self.destination, animated: true) 
      } else { 
       super.perform() 
      } 

     } 

回答

0

在故事板,選擇賽格瑞定製賽格瑞並選擇一種自定義SEGUE,使用默認行爲只是選擇顯示賽格瑞(如推)

enter image description here

+0

但在代碼執行(),我們如何知道它的自定義行爲。我想修改它只有當它的顯示(例如推) – andyPaul

+0

你不能從執行。你需要在故事板中創建不同的segue而不是代碼。一個像自定義賽格一樣的具有推送轉換和其他應該是默認賽格。 – Manoj