Cs.John Cs.John - 5 months ago 24
iOS Question

didSelectRowAtIndexPath in revealViewController

I'm working with

revealViewController
, and inside this revealViewController I wanted to create a
UITableView
with custom cells according to this tutorial: https://www.youtube.com/watch?v=EVJiprvRLoo

and here is my code:

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let vcName = identities[indexPath.row]
let viewController = storyboard?.instantiateViewControllerWithIdentifier(vcName)
self.navigationController?.pushViewController(viewController!, animated: true)
}


I'm using a storyboard, but I didn't get any issues, but it's not working.

I also tried to make a push segue to that view controller, but then my navigationViewController disappears, and I think it's would be easier by using code.

Sorry if my question is not accurate, but hope you can understand it.

Many Thanks.

Answer

Your self.navigationController? is nil. You should do something like this:

let vcName = identities[indexPath.row]
let viewController = storyboard?.instantiateViewControllerWithIdentifier(vcName)
let navVC = UINavigationController(rootViewController:viewController)

and then set front view controller by method of SWRevealViewController:

- (void)pushFrontViewController:(UIViewController *)frontViewController animated:(BOOL)animated;

self.revealViewController.pushFrontViewController(navVC, animated:true)