触摸按钮时,无法在幻灯片菜单中按下视图控制器

时间:2016-06-06 06:28:20

标签: ios swift pushviewcontroller

我使用KYDrawercontroller滑出菜单我在uitableview中触摸按钮时编写代码来推送viewcontroller但它没有推 这是我的代码

@IBAction func m01(sender: AnyObject) {
    let mainnav = self.storyboard!.instantiateViewControllerWithIdentifier("m02") as! UINavigationController //maindrawer
    let mainnav2 = self.storyboard!.instantiateViewControllerWithIdentifier("mm") as! page1ViewController //pagetopush
    mainnav.pushViewController(mainnav2, animated: true)

}

https://github.com/salution/slide

中的项目中查看

1 个答案:

答案 0 :(得分:0)

使用以下代码替换您的

@IBAction func m01(sender: AnyObject) {
    print("touched")
    let mainnav2 = self.storyboard!.instantiateViewControllerWithIdentifier("mm") as! page1ViewController
    let rootVC = UIApplication.sharedApplication().keyWindow?.rootViewController
    let childrenVC = rootVC?.childViewControllers
    let nc = childrenVC?.first as? UINavigationController
    if let DrawerTableViewController = navigationController?.parentViewController as? KYDrawerController{
        DrawerTableViewController.setDrawerState(.Closed, animated: true)
    }
    nc?.pushViewController(mainnav2, animated: true)

}

我更喜欢UIViewControllerAnimatedTransitioning协议来展示你的UI效果