Coder Social home page Coder Social logo

alert-blocks's Introduction

Category of UIAlertView that offers a completion handler to listen to interaction. This avoids the need of the implementation of the delegate pattern.

Installation instructions

  1. Import UIAlertView+Blocks.h in the desired classes of your project.

  2. 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];
    
  3. 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);
         }
     }];
    
  4. 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;
    
  5. You can see some examples in ViewController class.

Documentation

Execute appledoc appledoc.plist in the root of the project path to generate documentation.

alert-blocks's People

Contributors

emenegro avatar

Stargazers

Borja Igartua avatar Andrey Isaev avatar 国wei(Eric) avatar Dream007 avatar  avatar Titouan Van Belle avatar  avatar Jack avatar Chuck Kelly avatar AskMHX avatar Kyen avatar Marc Adams avatar Lee Probert avatar James Gupta avatar Luis Ramirez avatar  avatar Rodrigo avatar Alex Zak avatar jprothwell avatar Tim Kelly avatar 燎 avatar Javi Lorbada avatar  avatar Kevin avatar Joshua Kovach avatar Simone Leopizzi avatar Sangcheol Park avatar Baz Scott avatar  avatar Rubén Méndez avatar Luke Stringer avatar lqik2004 avatar Shuto Namiki avatar mayulu avatar Romain Briche avatar Sebastian  avatar  avatar

Watchers

mayulu avatar James Cloos avatar  avatar Zack Chung avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.