UIAlertView category for block expression
pod 'UIAlertViewBlockExtension'
- Block expression can be used for handling UIAlertView's clicks.
- Similar with UIAlertController in iOS 8.0
- Automatically, use UIAlertController if it is available (checking via [UIAlertController class])
UIAlertView *alertView = [UIAlertView alertViewWithTitle:@"title" message:@"message"];
[alertView addButtonWithTitle:@"OK" actionBlock:^(UIAlertView *alertView, NSInteger buttonIndex) {
// do something for OK
}];
[alertView addCancelButtonWithTitle:@"Cancel" actionBlock:^(UIAlertView *alertView, NSInteger buttonIndex) {
// do something for cancel
}];
[alertView show];
[UIAlertView showWithTitle:@"Title" message:@"message" cancelButtonTitle:@"cancel" action:^{
NSLog(@"cancel");
}];
[UIAlertView showWithTitle:@"Title" message:@"message" cancelButtonTitle:@"cancel" cancelAction:^{
NSLog(@"cancel");
} otherButtonTitle:@"OK" otherButtonAction:^{
NSLog(@"ok");
}];
- iOS version 4.0 or later