My app has a login screen before a user goes into the main view. I will do a presentModalViewController: if a user hasn’t logged in. In my main view’s viewDidLoad: I have a call to a REST API which requires the username and password of the user. Now, if the user has logged in then this is fine.
The problem is that even when the login view is shown, this main view behind the login view is still making a call to the REST API, although it’s not supposed to until the modal view is dismissed. So what is the best way to resolve this? Putting the API call into viewWillAppear:? A delegate?
viewWillAppearandviewDidAppearwill however get called afterviewDidLoad.You can use delegates. The login controller can give a call back to its delegate something like
-(void) loginController:(LoginViewController *) controller didLoginAnd here you can make your call to REST API.