簡體   English   中英

在快速的iOS 8中,當單擊一個單元格時,如何獲取它以打開另一個視圖控制器?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM