Coder Social home page Coder Social logo

janak-nirmal / alert-blocks Goto Github PK

View Code? Open in Web Editor NEW

This project forked from emenegro/alert-blocks

0.0 2.0 0.0 74 KB

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

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

Watchers

 avatar  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.