I am showing a login screen with an error, like:
_loginViewController.error = error;
[_navigationController presentModalController: _loginViewController
animated: YES];
In LoginViewController, I want to slide the error message onto the screen like this:
- (void)showErrorAnimated: (BOOL)animated;
{
_errorLabel.text = [_error localizedDescription];
[UIView beginAnimations: @"showError"
context: NULL];
CGRect frame = [_errorView frame];
frame.origin.y = 0; // starts at -frame.size.height
[_errorView setFrame: frame];
[UIView commitAnimations];
}
But I don’t know how to call this to match the timing of the view controller finishing it’s slide to the top of the screen begun by presentModalController:animated:.
How can I get this timing working?
You should use the
viewDidAppearmethod of your controller, which will be called the time the view is displayed.http://developer.apple.com/library/ios/documentation/uikit/reference/UIViewController_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40006926-CH3-SW17
Just be careful with
viewDidAppearbecause it is called whenever your view is shown. This means that if your controller presents a modal controller and then it is dismissed, theviewWillAppearandviewDidAppearmethods will be called again.