pushViewController not working

cristan lika picture cristan lika · Nov 22, 2016 · Viewed 11.7k times · Source

I am new to ios with swift and swrevealviewcontroller. i faceing a problem! in my slide menu (scene TableViewController Two blue line draw) each row when selected then should be open particuler scene (View controller) but unfortunatly it is not open . there have no error and didselectRowAt fire when i select row from the table but pushViewController not working .

  func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

        let dvcStoryBordId = menuViewIds[(indexPath.row - 1 )]

        let viewController = storyboard?.instantiateViewController(withIdentifier: dvcStoryBordId )

        self.navigationController?.pushViewController(viewController!, animated: true)
    }

Story Board

enter image description here

do i miss anything ? is it correct way ? self.

UPDATE :

self.navigationController is nil . is there any alternative ? or without navigation

Update:

Storyboard Id

menuViewIds = ["shareWithFriends","deliveryTracking", "controls", "support","myAccount"]

Run time view

enter image description here

Answer

Vikram Biwal picture Vikram Biwal · Nov 22, 2016

Try this:

   func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

         let dvcStoryBordId = menuViewIds[(indexPath.row - 1 )]
         let viewController = storyboard?.instantiateViewController(withIdentifier: dvcStoryBordId )
         var navigationController = UIApplication.sharedApplication().keyWindow?.rootViewController as! UINavigationController
         navigationController?.pushViewController(viewController!, animated: true)

   }