I want to make slide out menu. For this I have to create UINavigationViewController
which will control MenuViewController
(Table View) and ProfileViewControlle
r(Content View)
I want to set UINavigationViewController
like a rootViewController
, for this I wrote this code in AppDelegate.swift
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
let nav1 = UINavigationController()
let mainView = MainViewController(menuViewController: nil, contentViewController: nil) //ViewController = Name of your controller
nav1.viewControllers = [mainView]
self.window?.rootViewController = nav1
self.window?.makeKeyAndVisible()
return true
}
MainViewController
is my UINavigationViewController
.
But here I have error
nil is not compatible with expected argument type 'UIViewController'
What I should do?
You pass nil
here: MainViewController(menuViewController: nil, contentViewController: nil)
instead of some view controllers. That's probably the reason it doesn't compile.
You embed your MainViewController instance, which is already UINavigationController, into another one UINavigationController. That looks wrong too.
Here is an example:
LoginViewController *loginController = [[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:@"loginController"]; //or the homeController
UINavigationController *navController = [[UINavigationController alloc]initWithRootViewController:loginController];
self.window.rootViewController = navController;`
此错误意味着您不能将menuViewController和contentViewController设置为nil
,它们不是可选的
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.