How to use pushviewcontroller on uitableviewcell swift

3.1k views Asked by At

I create a new UITableviewcell.swift from UITableView, and I want to use alert button to push UITableView to other view.

I try to use some method of instantiateViewController as below:

let sb: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)

let vc = sb.instantiateViewController(withIdentifier: "MyViewController")

and I try:

  1. self.navigationController?.pushViewController (uitableviewcell has no member navigationController)
  2. as above, use self.window?.rootViewController? to replace Self ,but it's useless (my RootView is SWRevealViewController)

How can I do that?

2

There are 2 answers

0
payal solanki On

This may be help for you

override func tableView(tableView: UITableView!, didSelectRowAtIndexPath path: NSIndexPath!) {
    let secondViewController = self.storyboard.instantiateViewControllerWithIdentifier("SecondViewController") as SecondViewController
    self.navigationController.pushViewController(secondViewController, animated: true)
}
0
SnJ On

finally, the question has been solved (for me :D)

let sb: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)

let frontVC = sb.instantiateViewController(withIdentifier: "myVC1")
let frontNav = UINavigationController(rootViewController: frontVC)
let rearVC = sb.instantiateViewController(withIdentifier: "myVC2")

let rootVC = SWRevealViewController(rearViewController:rearVC ,frontViewController:frontVC)

self.window?.rootViewController = rootVC