[英]How to call (show) another View Controller when clicked on the cell of Table View in Swift
[英]In swift iOS 8 when a cell is clicked, how do I get it to open another view controller?
我剛開始進行快速編程,已經嘗試了幾個小時。 任何幫助都將不勝感激。
只是覆蓋: didSelectRowAtIndexPath
override func tableView(tableView: UITableView!, didSelectRowAtIndexPath path: NSIndexPath!) {
let secondViewController =
self.storyboard.instantiateViewControllerWithIdentifier("SecondViewController")
as SecondViewController
self.navigationController.pushViewController(secondViewController, animated: true)
}
若要擴展@Epic Defeater的注釋,如果您的表視圖控制器和目標視圖控制器在同一情節提要中,請從表單元格將控件拖動到目標視圖控制器。 這是一個問題,它可以執行@Klevison Matias的代碼,但是您的參與較少。
segue需要一個唯一的標識符,並且在表視圖控制器中,您必須實現prepareForSegue:sender:
您需要創建要打開的View Controller的實例,然后過渡到該View Controller-大概是通過將View Controller“推”到導航堆棧(導航控制器)上。
例如...
let nextViewController: MyViewController = MyViewController()
self.navigationController.pushViewController(nextViewController, animated:true)
只需將單元格中的segue添加到要與其連接的視圖控制器即可。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.