I have a login screen with with ip, port, username and password text fields to get the values and connect to a ASMX webservice. Connecting works flawless.
What's the best way to realize a login cycle? Define a blank view controller as the rootViewController and implement a protocol in the LoginViewController to delegate to this blank viewController and check the login credentials there and if succeeded to link to the main view? I'm into clean and decoupled code. So I decided to use the Mediator Design Pattern.
I have a JSONHelper class who will do the serialization. But I don't know whether to delegate to the loginVC or use an instance of it in the blank view controller (if it's the right way).
You may want to start with the view you want to present at first and check if authentication is needed. If it is, present a view controller modally without animation. Let's say you have the following view controllers:
As soon as the app launches, you can ask the AuthenticationHelper to log the user in. If it already has the username and password stored, it can do it automatically without presenting the login screen. If it doesn't, it can then show LoginViewController.
Note the following:
Once the login is successful you could just preform a manual segue from it to the main view controller. Thats only a very small amount of code. No delegates and such. Just something like this:
if (login){
[self performSegueWithIdentifier:@"YOUR SEGUE ID"];
}
Than method then calls the prepareForSegue
method, where you could pass values to the main view controller if you like. Xcode will take care of all the memory management for you and the recycling of views.
Of course, you need to be using storyboards for this. Hope this helps.
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.