Category of UIAlertView
that offers a completion handler to listen to interaction. This avoids the need of the implementation of the delegate pattern.
-
Import
UIAlertView+Blocks.h
in the desired classes of your project. -
You has to create the alert the regular way
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Test alert view" message:@"This is a test of an alert view with a completion block instead of the delegate pattern" delegate:nil // Can be another value but will be overridden when showing with handler. cancelButtonTitle:@"Cancel" otherButtonTitles:@"Button 1", @"Button 2", nil];
Now you have a new method to show the alert that passes the completion handler
[alert showWithHandler:^(UIAlertView *alertView, NSInteger buttonIndex) { if (buttonIndex == [alertView cancelButtonIndex]) { NSLog(@"You clicked the cancel button (index %i)", buttonIndex); } else { NSLog(@"You clicked the button at index %i", buttonIndex); } }];
There are some utility selectors to show common alerts.
// Utility selector to show an alert with a title, a message and a button to dimiss. + (void)showWithTitle:(NSString *)title message:(NSString *)message handler:(UIAlertViewHandler)handler; // Utility selector to show an alert with an "Error" title, a message and a button to dimiss. + (void)showErrorWithMessage:(NSString *)message handler:(UIAlertViewHandler)handler; // Utility selector to show an alert with a "Warning" title, a message and a button to dimiss. + (void)showWarningWithMessage:(NSString *)message handler:(UIAlertViewHandler)handler; // Utility selector to show a confirmation dialog with a title, a message and two buttons to accept or cancel. + (void)showConfirmationDialogWithTitle:(NSString *)title message:(NSString *)message handler:(UIAlertViewHandler)handler;
You can see some examples in
ViewController
class.Execute
appledoc appledoc.plist
in the root of the project path to generate documentation.alert-blocks's People
Forkers
janak-nirmal protez aalesia indevizible code4bones zackhsuan phoenixbull okulak jerez hdinguyenRecommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.