0

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?

Dheeraj D
  • 4,386
  • 4
  • 20
  • 34
SnJ
  • 19
  • 1
  • 2
  • Take a look at this: http://stackoverflow.com/questions/30773529/open-new-view-controller-by-clicking-cell-in-table-view-swift-ios. The next time first do some reseach before asking the question. – Mar-k Jan 05 '17 at 10:00
  • thank you for your reply much appreciated, I searching for it over 3 days – SnJ Jan 05 '17 at 10:28
  • sorry for my stupidity – SnJ Jan 05 '17 at 10:29

2 Answers2

0

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)
}
Miknash
  • 7,888
  • 3
  • 34
  • 46
0

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
SnJ
  • 19
  • 1
  • 2