Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Login Screen with Storyboarding possible?

I am playing around with the new iOS 5 features and trying to rewriting one of my apps as pure iOS 5 app using the new storyboarding feature.

To cut a long story short, I have a start screen where the app tries to connect to a server if the user saved some login data, if not, it should ask for them.

Here is how I would do it. I create a Viewcontroller which is doing the connection thing in the viewDidLoad method. If there is no login data or the login is not successful, I need a to do a manual segue to the login screen.

Now is this even possible, or do I need 2 story boards for that ?

like image 908
eemceebee Avatar asked Oct 27 '11 09:10

eemceebee


People also ask

What is the use of storyboard in Xcode?

The Storyboard feature of Xcode allows for the navigational flow between the various views in an iOS application to be visually constructed without the need to write code.

Why are storyboards great features in iOS development?

Storyboards allow you to prototype and design multiple view controller views within one file, and also let you create transitions between view controllers.

How does Main storyboard connect to ViewController?

Create a new IBOutlet called shakeButton for your storyboard button in your ViewController. swift file. Select the shake button in Interface Builder. Then hold down the control button ( ⌃ ) and click-drag from the storyboard button into your ViewController.


2 Answers

I have solved it by putting a login view without any segues (to or from it) like in the screenshot below:

enter image description here

Then, I used a custom class in the tab bar controller to show it whenever I need it.

In the tab bar controller class, I use 'viewDidLoad' to fire up the login view. To show the modal view, I do have a singleton thingy that stores some state, say BOOL isAuthenticated, where I do the magic:

- (void) performLoginIfRequired: (UIViewController *) source {

   if (!self.isAuthenticated) {

       NSLog(@"Is not authed");

       UIStoryboard *storyboard = [UIApplication sharedApplication].delegate.window.rootViewController.storyboard;

       UIViewController *loginController = [storyboard instantiateViewControllerWithIdentifier:@"loginScreen"];

       [source presentModalViewController:loginController animated:YES];

   } else {
       NSLog(@"Is authe");

   }
}

And, in my case, I wanted it to be shown when the app first starts, but also when it enters foreground again. So, I registered my tab bar controller with the notification center, so I get notified if the app is coming back:

-(void)viewDidLoad {
    [[NSNotificationCenter defaultCenter] addObserver:self  selector:@selector(willEnterForeground:) name:UIApplicationWillEnterForegroundNotification object:nil];
}

In the willEnterForeground method, I do:

-(void) willEnterForeground: (NSNotification *)notification {
    [[myStateThingy defaultState] performLoginIfRequired:self]; 
}
like image 189
Papick G. Taboada Avatar answered Sep 20 '22 17:09

Papick G. Taboada


It sounds like you need to use the performSegueWithIdentifier method. Make sure both views are in the same storyboard, link them together using a Push segue, and give that segue a name. Then, from your first view controller's code simply call the performSegueWithIdentifier to perform a manual segue.

Hope this helps!

See also: Conditionally following a segue

Cheers, Jesse L. Zamora

like image 28
Jesse L. Zamora Avatar answered Sep 18 '22 17:09

Jesse L. Zamora