- (IBAction)showAlert
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Hello,World"
message:@"This is my first app!"
delegate:nil
cancelButtonTitle:@"Awesome"
otherButtonTitles:nil];
[alertView show];
}
start the next round after we click OK pp104
We can ask the alert view to send us a message when it is being closed. In the mean time, we simply call Update and nextRound methods. when the user finally taps the OK button on the alert view, the alert will remove itself from the screen and send us that message.
This is also known as the listener pattern or observer pattern. Our view controller listens to events coming from the alert view. In proper iOS terminology such listeners are named delegates and that's the term we'll be using.
in .h
@interface BullsEyeViewController : UIViewController <UIAlertViewDelegate>
This tells the app that our view controller is now a delegate of UIAlertView
//This is the delegate method that is called by the alert view when the user closes it.
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
[self startNewRound];
[self updateLables];
}
Delegate, declare the conformance in interface not implementation
Delegates in two steps
1 You declare yourself capable of being a delegate. (conform to some protocol)
1 You let the object in question, in this case the UIAlertView, know that you wish to become its delegate. (set delegate:self i.e. in controller)