![](/img/trans.png)
[英]Multiple Segues to one ViewController with NavigationController?
[英]How to add multiple segues from one viewController
我有一個UI視圖控制器(viewControllerOne),其中有一個表視圖。 我有一個從單元格中的按鈕到另一個viewController(viewControllerTwo)的提示。
這很好。
現在,我有第三個視圖控制器,並且希望從View Controller中的另一個按鈕中選擇一個。 如何從一個視圖控制器轉到多個不同的viewController。
第一個Segue應該位於VC本身(而不是單元格內的按鈕)與目標VC之間,以便能夠在prepareforSegue
發送數據,因此從VC1的黃色圖標同時拖動到VC2和VC3並提供一個toTocond & 然后分別在代碼中執行
// change segue identifier if you want to third
self.performSegue(withIdentifier: "toSecond ", sender:nil)
UITableViewCell
Segue應該以編程方式完成。 didSelectCell at indexPath
方法中使用didSelectCell at indexPath
。 調用此方法時,應基於indexPath執行segue。 我個人建議使用結構數組來跟蹤UITableViewCells
。 例如:
struct tableViewCell {
var cell: UITableViewCell
var segue: String
}
var cells: Array<Array<tableViewCell>> = [];
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: IndexPath) {
self.performSegue(withIdentifier: cells[indexPath.section][indexPath.row].segue);
}
抱歉,如果有任何錯別字,該代碼不是用xcode編寫的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.