我有tableViewController从Parse中提取数据。这会调用UINavigationControllerDelegate的继承。
我想在用户点击一个单元格时推送一个新的视图控制器。这似乎是一项简单的任务,但我无法让它发挥作用。我首先尝试在我的故事板中简单地制作推送segue但是当我点击单元格时没有任何反应。我试图以编程方式执行此操作但是当我点击单元格时应用程序崩溃了。我在实例化行上遇到断点错误:
import UIKit
import Foundation
import Parse
class PFViewController: PFQueryTableViewController, UITableViewDataSource, UINavigationControllerDelegate {
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let vc: Podcast = self.storyboard?.instantiateViewControllerWithIdentifier("Podcast") as Podcast
self.navigationController?.pushViewController(vc, animated: true)
}
}
有什么想法吗?
答案 0 :(得分:1)
要创建segue,请从TableViewController按住Ctrl键拖动到目标viewController:
然后选择segue并在属性检查器中为其指定一个标识符:
现在您可以在代码中执行此segue:
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let cell = tableView.cellForRowAtIndexPath(indexPath)
tableView.deselectRowAtIndexPath(indexPath, animated: true)
performSegueWithIdentifier("mySegue", sender: cell)
}