Reputation: 893
I have tableViewController which pulls data from Parse. This calls inherits from UINavigationControllerDelegate.
I want to push a new view controller when the user taps on a cell. It seems like a simple task but I can't get it to work. I have first tried just simply making a push segue in my storyboard but nothing happens when I tap on the cell. I have tried to do it programmatically but the app crashes when I tap on the cell. I get a breakpoint error on the instantiation line:
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)
}
}
Any ideas please?
Upvotes: 1
Views: 1155
Reputation: 23078
To create the segue, ctrl-drag from the TableViewController to the destination viewController:
Then select the segue and give it an identifier in the property inspector:
Now you are able to perform this segue in code:
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let cell = tableView.cellForRowAtIndexPath(indexPath)
tableView.deselectRowAtIndexPath(indexPath, animated: true)
performSegueWithIdentifier("mySegue", sender: cell)
}
Upvotes: 1