Latest 1.0
Homepage https://github.com/RuiAAPeres/UITextField-DelegationBlocks
License MIT
Platforms ios 5.0, requires ARC
Authors

UITextField+DelegationBlocks

A simple category that allows you to add completion blocks for your UITextField on a per instance basis. What this means is that you can do something like this:

[[self nameTextField] addTextFieldShouldChangeCharactersInRangeWithBlock:^BOOL(UITextField *textField, NSRange range, NSString *replacementString)
{
    self handleNameTextField:textField];
    return YES;
}];

[[self passwordTextField] addTextFieldShouldChangeCharactersInRangeWithBlock:^BOOL(UITextField *textField, NSRange range, NSString *replacementString)
{
    [self handlePasswordTextField:textField];
    return YES;
}];

This is specially useful to avoid forking your code. Yup, I hate ifs and switches.


Adding UITextField+DelegationBlocks to your project

  • Just add the two files inside your project (UITextField+DelegationBlocks.h and UITextField+DelegationBlocks.m).

Or

  • Cocoapods: pod ‘UITextField+DelegationBlocks’, ‘~> 1.0’`

Finally import the category where you want to use it:

  • #import "UITextField+DelegationBlocks.h"

Usage

Currently I added this methods:

- (void)addTextFieldShouldChangeCharactersInRangeWithBlock:(TextFieldShouldReturnShouldChangeCharactersInRangeBlock)block;
- (void)addTextFieldShouldReturnWithBlock:(TextFieldShouldReturn)block;
- (void)addTextFieldShouldBeginEditingWithBlock:(TextFieldShouldReturn)block;
- (void)addTextFieldDidBeginEditingWithBlock:(TextFieldDidBeginEditing)block;
- (void)addTextFieldDidEndEditingWithBlock:(TextFieldDidEndEditing)block;

I will add more if I see a need to it (I am using this on my own projects), or anyone has the need for it. Still, if you want, you can always make a pull request.


License

This code is distributed under the terms and conditions of the MIT license.

Bitdeli Badge

Latest podspec

{
    "name": "UITextField+DelegationBlocks",
    "version": "1.0",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "summary": "Add blocks, as per a single instance basis, to your UITextFields",
    "homepage": "https://github.com/RuiAAPeres/UITextField-DelegationBlocks",
    "authors": {
        "R. Peres": "[email protected]"
    },
    "source": {
        "git": "https://github.com/RuiAAPeres/UITextField-DelegationBlocks.git",
        "tag": "1.0"
    },
    "platforms": {
        "ios": "5.0"
    },
    "source_files": "*.{h,m}",
    "requires_arc": true
}

Pin It on Pinterest

Share This