-1

I'm not sure how to reuse a login view anywhere in my app...so when I click login on any screen I can just login and then have the view dismiss...I guess I'm not finding tutorial about modally displaying a common view across the entire app...

BostonMacOSX
  • 1,369
  • 2
  • 17
  • 38
  • Are you using `UIStoryboard` ? – Laffen Sep 20 '16 at 12:47
  • -1. Did you search enough? I highly recommend that you see [this](http://stackoverflow.com/questions/19962276/best-practices-for-storyboard-login-screen-handling-clearing-of-data-upon-logou) question, It's in Objective-C but the logic is EXACTLY the same. ALSO see this [SWIFT video tutorial](https://www.youtube.com/watch?v=uKXyLmYA0-c&list=PLoN_ejT35AEipRnSHSv5wlHGyjOnHReqx). Basically where ever you want you have to use `presentViewController` and then dismiss it after you're done with it.FYI login screens are *usually* to be presented modally... as they don't belong to the natural flow. – mfaani Sep 20 '16 at 13:46

2 Answers2

0

This should probably work. Define you view in login view controller. let storyboard = UIStoryboard(name: "Main", bundle: nil) let vc = storyboard.instantiateViewControllerWithIdentifier("loginViewController") as! UIViewController present whenever you want to show login screen.

self.presentViewController(vc, animated: true, completion: nil)
Urvi Mali
  • 86
  • 7
-1

Try this..(You can make single instance of loginViewController and use this code any where from app.)

UIStoryboard *mainStoryboard = [UIStoryboard  storyboardWithName:@"main" bundle:nil];
UIViewController *loginViewController = [mainStoryboard instantiateViewControllerWithIdentifier:@"loginViewController"];
UIViewController *lastPresentedViewController =  [[[UIApplication sharedApplication] keyWindow] rootViewController];

while (lastPresentedViewController.presentedViewController) {
    lastPresentedViewController = lastPresentedViewController.presentedViewController;
}

[lastPresentedViewController presentViewController:loginViewController animated:true completion:nil];
Rajesh Choudhary
  • 1,340
  • 8
  • 12