[英]Create a segue and attach it between two view controllers through Swift?
我們如何在不使用情節提要的情況下以編程方式快速創建序列。 由於應用程序的結構,我無法使用情節提要,因此我需要知道如何以編程方式進行操作。
本質上,我要做的就是創建一個序列,並將其附加在源和目標之間。
到目前為止,我已經創建了RollSegue類,它是UIStoryboardSegue的子類。 現在,我正在嘗試執行以下操作:
var seg: RollSegue = UIStoryboardSegue("roll", self, destination)
我也嘗試過:
var seg: UIStoryboardSegue = UIStoryboardSegue("roll", self, destination)
這些代碼行運行良好,但是當我嘗試調用performSegue方法時,出現錯誤:
Receiver (<Home1: 0x7fc84b573fd0>) has no segue with identifier 'roll'
實際上,您只能在情節提要中設置segue標識符。 因此,如果要在兩個控制器之間導航,則應使用
func pushViewController(_ viewController: UIViewController, animated animated: Bool)
要么
func presentViewController(_ viewControllerToPresent: UIViewController, animated flag: Bool, completion completion: (() -> Void)?)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.