implement login screen before swrevealcontroller

2019-03-16 22:46发布

问题:

I've just started learning IOS development, I've successfully implemented the SWRevealViewController by following a given tutorial online all is working as expected.

I've then decided to add a login screen, which would be the first page the user see's when the application is run. The steps I took are a follows:

  1. Dropped a UIViewController onto the story board
  2. Set this as my 'is initial view controller'
  3. Added a button to this new view and created a seque for testing purposes

But when I click this button it does nothing, so after searching the web and trying to figure this one by my self unfortunately I've been unsuccessful due to my lack of knowledge on this, would someone be kind enough to give me some pointers on what I need to change if anything, or what sections need to me modified to make this flow work as expected?

Below is a screen grab of my current story board.

Update

After adding the relevant code the app delegate file I still receieve this error message:

回答1:

Step-1

embed your login VC to NavigationController.

Step-2

on your login button action set the segue type as Modal and call as

 @IBAction func btnLogin(sender: AnyObject) {

    self.performSegueWithIdentifier("openSWL", sender: self)
  }

For flow understand purpose

For sample Project you can download here



回答2:

The Storyboard arrangement looks good. I have used SWRevealController like below:

After you login (performing login service or some login process) write below code. This code will change current rootViewController (In your case it is LoginViewController) to SWRevealController. So that it will work. And when ever you do logout change rootViewController to LoginViewController.

SWRevealViewController *controller = (SWRevealViewController *)[self.mainStoryboard instantiateViewControllerWithIdentifier:@"RevealViewController"];
[self.window setRootViewController:controller];

Do not forget to assign StoryboardID = "RevealViewController" in Storyboard for SWRevealViewController.

Swift Code:

Add below function to your AppDelegate.swift file:

func changeRootViewControllerToSWRevealViewController () {
    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let controller = storyboard.instantiateViewControllerWithIdentifier("RevealViewController")
    if let window = self.window{
        window.rootViewController = controller
    }
}

// Call above function in your login button action method like below:

    let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
    appDelegate.changeRootViewControllerToSWRevealViewController()