The displayViewController () function always returns nil

I am having problems with revealViewControllerin Xcode 7.2 and iOS 9.2.

My application starts with a controller built into the navigation controller to enter the system. After logging in or having a login token, I go to another view controller built into the navigation controller with the following code:

let homePage = self.storyboard?.instantiateViewControllerWithIdentifier("HomeViewController") as! HomeViewController
let homePageNav = UINavigationController(rootViewController: homePage)
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
appDelegate.window?.rootViewController = homePageNav

In this home view controller, I would like to have a left navigation menu with SWRealViewController.

I had a view SWRealViewControllerrelated to sw_frontmy home navigation controller and the following code:

if (self.revealViewController() != nil) {
    self.menuButton.target = self.revealViewController()
    self.menuButton.action = "revealToggle:"
self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())

But it self.revealViewController()always returns nil, so it does not work.

, - revealViewController (, ), , .

+4
3

, revealViewController nil segues stroyboard.

. , .

login vc, , :

AppDelegate

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

   var rootVCStoryboardId = userIsLoggedin ? "SWRevealViewController" : "LoginViewController"
   self.window?.rootViewController = UIStoryboard(name: Storyboards.main, bundle: NSBundle.mainBundle()).instantiateViewControllerWithIdentifier(rootVCStoryboardId)

SWRevealViewController - stroyboard SWRevealViewController, LoginViewController - ( , ).

+4

- , , , .

    let storyboard = UIStoryboard(name: "Main", bundle: nil)

    let sw = storyboard.instantiateViewControllerWithIdentifier("SWRevealViewController") as! SWRevealViewController

    self.view.window?.rootViewController = sw

    let destinationController = self.storyboard?.instantiateViewControllerWithIdentifier("StoryboardID") as! NameOfViewController

    let navigationController = UINavigationController(rootViewController: destinationController)

    sw.pushFrontViewController(navigationController, animated: true)
+3

If you skipped the login scene based on current user information, make sure to create a storyboard instance with SWRevealViewController. See below code for reference:

if User.currentUser != nil {
        //There is a current user
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let vc = storyboard.instantiateViewControllerWithIdentifier("SWRevealViewController")
        window?.rootViewController = vc
    }
    else{
        //No current user
    }
0
source

Source: https://habr.com/ru/post/1625788/


All Articles