[英]Swift - Open ViewController on Tapping a TableViewCell
我有一個具有相同單元格的 tableView。 選擇其中之一后,我想打開另一個 ViewController。 我試過這個代碼:
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: IndexPath) {
let destination = EditViewController()
navigationController?.pushViewController(destination, animated: true)
}
但它沒有打開另一個 ViewController。 你能給我一個提示嗎?
很可能你只是沒有navigationController
控制器 - 使用而present
來顯示視圖控制器:
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: IndexPath) {
let destination = EditViewController()
self.present(destination, animated: true, completion: nil)
}
或者,如果您想要推送 viewController,請確保將tableViewController
嵌入到UINavigationController
。
只需進入故事板,選擇您啟動視圖控制器,然后單擊編輯器>嵌入並選擇導航控制器,然后您的代碼將起作用。 這意味着您已經從初始視圖控制器為視圖控制器設置了導航堆棧。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.