Coder Social home page Coder Social logo

janak-nirmal / action-sheet-blocks Goto Github PK

View Code? Open in Web Editor NEW

This project forked from emenegro/action-sheet-blocks

0.0 2.0 0.0 78 KB

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

action-sheet-blocks's Introduction

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

Installation instructions

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

  2. You has to create the sheet the regular way

     UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"Test"
     												   delegate:nil // Can be another value but will be overridden when showing with handler.
     										  cancelButtonTitle:@"Cancel"
     									 destructiveButtonTitle:@"Delete"
     										  otherButtonTitles:@"Option 1", @"Option 2", nil];
    
  3. Now you have several new methods to show the sheet passing the completion handler.

     [sheet showInView:view
               handler:^(UIActionSheet *actionSheet, NSInteger buttonIndex) {
                   
                   if (buttonIndex == [actionSheet cancelButtonIndex]) {
                       
                       NSLog(@"Cancel button index tapped");
                       
                   } else if (buttonIndex == [actionSheet destructiveButtonIndex]) {
                       
                       NSLog(@"Destructive button index tapped");
                       
                   } else  {
                       
                       NSLog(@"Button %i tapped", buttonIndex);
                   }                      
               }];
    
  4. For each method in UIActionSheet that shows a sheet there is a new method with the same signature but that also passes the handler.

     - (void)showInView:(UIView *)view handler:(UIActionSheetHandler)handler;
     - (void)showFromBarButtonItem:(UIBarButtonItem *)item animated:(BOOL)animated handler:(UIActionSheetHandler)handler;
     - (void)showFromRect:(CGRect)rect inView:(UIView *)view animated:(BOOL)animated handler:(UIActionSheetHandler)handler;
     - (void)showFromTabBar:(UITabBar *)view handler:(UIActionSheetHandler)handler;
     - (void)showFromToolbar:(UIToolbar *)view handler:(UIActionSheetHandler)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.

action-sheet-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.