我是 swift 和 swrevealviewcontroller 的新手。我正面临一个问题!在我的幻灯片菜单(场景TableViewController两个蓝线绘制)选中的每一行然后应该打开particule scene
(查看控制器)但不幸的是它没有打开。当我从表中选择行但pushViewController不工作时,没有错误和didselectRowAt
触发。
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)
}
故事板
我错过了什么吗?这是正确的方法吗?自更新:
self.navigationController
是nil
。还有其他选择吗?或没有导航
更新
故事板ID
menuViewIds = ["shareWithFriends","deliveryTracking", "controls", "support","myAccount"]
运行时视图
答案 0 :(得分:1)
试试这个:
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)
}
答案 1 :(得分:0)
试试这个:
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)!
}