从 TabBar Controller 呈现导航控制器
Presenting a navigation crontroller from TabBar Controller
我创建了一个以我的 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'
您需要这样做:
let navController = UINavigationController(rootViewController: viewController!)
navController.setViewControllers([viewController], animated: true)
self.presentViewController(navController, animated: true, completion: nil)
假设标识符为"Dashboard"
的storyboard view controller是UINavigationController
,直接present即可:
func showView() {
let viewController = self.storyboard?.instantiateViewControllerWithIdentifier("Dashboard")
presentViewController(viewController, animated: true, completion: nil)
}
关闭(从呈现视图控制器):
dismissViewControllerAnimated(true, completion: {});
关闭(从显示的视图控制器):
self.presentingViewController.dismissViewControllerAnimated(true, completion: {});
我创建了一个以我的 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'
您需要这样做:
let navController = UINavigationController(rootViewController: viewController!)
navController.setViewControllers([viewController], animated: true)
self.presentViewController(navController, animated: true, completion: nil)
假设标识符为"Dashboard"
的storyboard view controller是UINavigationController
,直接present即可:
func showView() {
let viewController = self.storyboard?.instantiateViewControllerWithIdentifier("Dashboard")
presentViewController(viewController, animated: true, completion: nil)
}
关闭(从呈现视图控制器):
dismissViewControllerAnimated(true, completion: {});
关闭(从显示的视图控制器):
self.presentingViewController.dismissViewControllerAnimated(true, completion: {});