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

10
  • 2
    Please debug and check self.navigationController is not null. Commented Nov 22, 2016 at 6:56
  • @user4887505 self.navigationController is nil . what should i do Commented Nov 22, 2016 at 7:10
  • 1
    Make your "menu Controller" with "navigation Controller". Commented Nov 22, 2016 at 7:19
  • 1
    from the image of your storyboard it seems that your Slide TableViewController (the one with the blue lines) is not wrapped in a navigation controller, so therefore the navigationController is nil. So either you could wrap/embed it in a navigationController or you could just use present on the Slide TableViewController. Commented Nov 22, 2016 at 7:22
  • 1
    @pbodsk not yet just a good idea Commented Nov 22, 2016 at 7:52

2 Answers 2

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)

   }
Sign up to request clarification or add additional context in comments.

10 Comments

it is working but back button not showing .. what should i do ?
please check now.
sorry please check now.
Could not cast value of type 'LifeFast.ViewController' (0x10e127910) to 'UINavigationController' (0x1109adf18).
|
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)!
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.