从TabBar控制器呈现导航crontroller

时间:2015-11-19 00:25:02

标签: ios swift uiviewcontroller uitabbarcontroller

我创建了一个自定义按钮,我以TabBar控制器为中心。我想用它来呈现一个模块化附加到导航控制器的视图控制器。但是,我一直收到错误,错误说我无法推动。然而,我不是在推动。我正在介绍

 func showView() {
    print("We are here ohhh")
    let viewController = self.storyboard?.instantiateViewControllerWithIdentifier("Dashboard")

    //Creating a navigation controller with viewController at the root of the navigation stack.
    let navController = UINavigationController(rootViewController: viewController!)
    self.navigationController?.presentViewController(navController, animated: true, completion: nil)
    //self.presentViewController(navController, animated:true, completion: nil)
}

The Error

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Pushing a navigation controller is not supported'

2 个答案:

答案 0 :(得分:2)

假设标识为"Dashboard"的情节提升视图控制器为UINavigationController,您可以直接呈现它:

func showView() {
    let viewController = self.storyboard?.instantiateViewControllerWithIdentifier("Dashboard")
    presentViewController(viewController, animated: true, completion: nil)
}

解雇(从呈现视图控制器):

dismissViewControllerAnimated(true, completion: {});

解雇(从提供的视图控制器):

self.presentingViewController.dismissViewControllerAnimated(true, completion: {});

答案 1 :(得分:-2)

你需要这样做:

let navController = UINavigationController(rootViewController: viewController!)
navController.setViewControllers([viewController], animated: true)
self.presentViewController(navController, animated: true, completion: nil)
相关问题