我有 CenterTableViewController
、左和右
中心是应用程序启动时的主视图,左侧和右侧是侧菜单,在导航 Controller 上滑动或单击时打开。按钮
左侧和右侧的 TableViewController
都有其项目数量,右侧的大约有 10 个。当单击这 10 个项目之一时,需要弹出一个特定的 ExampleViewController
。 ViewController
出现时没有导航 Controller (我需要它),在该导航 Controller 中我需要一个后退按钮,它将让我返回到 CenterTableViewController
。
到目前为止,我到达了RightTableViewController
,在它的类witch中命名相同,我有这个方法
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
switch (indexPath.row){
case 0:
break;
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
let VC = self.storyboard?.instantiateViewControllerWithIdentifier("Kurs_Evra") as! KursEvraViewController
self.navigationController?.pushViewController(VC, animated: true)
break;
case 6:
break;
case 7:
break;
case 8:
break;
case 9:
break;
default:
println("JBG")
}
}
在情况 5 中,它打开我需要的 ViewController
,但它在 RightTableViewController
而不是 Center 中打开(因为“self”部分)。
另外,当它打开时,如何在刚刚打开的 ViewController
上创建导航 Controller 和后退按钮?
最佳答案
这并不难。
转到右侧或左侧菜单,在类创建方法 didSelectRowAtIndex 路径中,然后使用上面的 switch 语句。
然后,如果发布您需要的代码,这就是您在导航堆栈和主 ViewController 上方发布新 Storyboard的方式
让Example = self.storyboard?.instantiateViewControllerWithIdentifier("ExampleViewController") as!示例ViewController
让 navController = UINavigationController(rootViewController: 示例)
最后...
self.presentViewController(navController,动画:true,完成:nil)
使用“present”将打开您创建的新 Controller ,在本例中为ExampleViewController,它将位于新导航堆栈中的第一个。如果您希望关闭或模拟后退按钮,只需将操作连接到按钮并调用:
self.dismissViewController(navController,动画:true,完成:nil)
关于ios - 从侧面菜单中选择项目时打开特定的 ViewController?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31574849/