如何在uitableviewcell swift上使用pushviewcontroller

时间:2017-01-05 09:58:49

标签: ios swift uitableview pushviewcontroller

我从UITableviewcell.swift创建了一个新的UITableView,我想使用提醒按钮将UITableView推送到其他视图。

我尝试使用instantiateViewController的某种方法,如下所示:

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

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

我试试:

  1. self.navigationController?.pushViewController(uitableviewcell没有成员navigationController)
  2. 如上所述,使用self.window?.rootViewController?替换Self,但它没用(我的RootViewSWRevealViewController
  3. 我该怎么做?

2 个答案:

答案 0 :(得分:0)

这对您有帮助

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

答案 1 :(得分:0)

最后,问题已经解决了(对我来说: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