简体   繁体   中英

implement login screen before swrevealcontroller

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:

在此处输入图片说明

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

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()

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM