ios - 从侧面菜单中选择项目时打开特定的 ViewController?

标签 ios swift uinavigationcontroller viewcontroller

我有 CenterTableViewController、左和右 中心是应用程序启动时的主视图,左侧和右侧是侧菜单,在导航 Controller 上滑动或单击时打开。按钮 左侧和右侧的 TableViewController 都有其项目数量,右侧的大约有 10 个。当单击这 10 个项目之一时,需要弹出一个特定的 ExampleViewControllerViewController 出现时没有导航 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/

相关文章:

iphone - UIWebview xml 文件

ios - 单击 + Swift 预加载 UISearchBar 显示结果

ios - 如何在 iOS 10 中将 textView 的高度存储在数组或字典中

ios - 在iOS上 flutter 蓝牙问题

ios - SwiftUI - 如何在 SwiftUI 中弹出特定 View ?

iphone - 从纵向旋转到横向时如何更改 UIBarButtonItem 大小?

ios - 如果用户拒绝访问相机,如何防止 WKWebView 显示相机模式?

ios - 在 Xcode 4.6.3 中安装自定义字体

ios - 如何设置按钮的样式以具有透明文本?

ios - 单击推送通知时正确重定向到选项卡栏导航 Controller 内的 View Controller