Currently I am using the following code to present a UIAlertView:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@\"Today\'s Entry Complete\"
You need to setup the delegate
for your UIAlertView
, before showing it. Then do the work in the delegate callback as such:
-(void)alertView:(UIAlertView*)alert didDismissWithButtonIndex:(NSInteger)buttonIndex;
{
if ([[alert buttonTitleAtIndex] isEqualToString:@"Do it"]) {
// Code to execute on Do it button selection.
}
}
My CWUIKit project over at https://github.com/Jayway/CWUIKit has an addition to UIAlertView
that allow you to do the same thing but with blocks. Redusing the same operation for both creating, showing and handling the alert to this:
[[UIAlertView alertViewWithTitle:@"My Title"
message:@"The Message"
cancelButtonTitle:@"Cancel"
otherTitlesAndAuxiliaryActions:@"Do it",
^(CWAuxiliaryAction*a) {
// Code to execute on Do it button selection.
}, nil] show];