I’m a web developer tasked with building a basic iOS app for internal use. A number of functions in the app require authentication, and I’ve successfully built the login view/controller which calls a webservice, authenticates the user etc etc.
I can currently load the “LoginView” with a button click and after authenticating the user, dismiss the view from the view stack returning to the original view, now with established credentials. None of that is my issue.
Now I’m looking for the equivalent of doing a ‘redirect’ as I would in developing for the web. I need to load the LoginView from any function in my application where authentication is required, and on success, load some other view which would be “passed in” (on the web I would provide a redirect Url) to the LoginView. I feel like this is a simple thing, and must be done all the time, but can not find a good example or explanation of this. I’m certain my obvious newbiness is preventing me from even searching for the right terms.
Hopefully someone can decipher my poor, yet best attempt at explaining what I am looking for. Thank you in advance.
This is the perfect job for delegates. In your login view controller interface (please note I’m writing this off the top of my head so there might be a few typos/missing semi-colons etc:
And then in your implementation file, once you have established that the webservice has responded to the login request, you can call:
So every time you create an instance of your login view controller, you can assign the “parent” view controller as the delegate and then conform to the
<LoginControlDelegate>by implementing the methodloginDidSucceed:And the loginDidSucceed method: