6

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

cristan lika
  • 415
  • 1
  • 7
  • 22

2 Answers2

1

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)

   }
Vikram Biwal
  • 2,618
  • 1
  • 25
  • 36
0

Try This:

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

         let dvcStoryBordId = menuViewIds[indexPath.row]
         let viewController = storyboard?.instantiateViewController(withIdentifier: dvcStoryBordId )
         let vc = windowRootViewController() as! SWRevealViewController
         let nvc = vc.frontViewController as! UINavigationController
         nvc.pushViewController(viewController, animated: true)
   } 

WindowRootVC() :

func windowRootViewController() -> UIViewController {
    return (UIApplication.shared.delegate?.window??.rootViewController)!
}
Uday Babariya
  • 1,031
  • 1
  • 13
  • 31