Get Updates By E-mail 

Article Written By:
Johann Dowa

iOS UIControl Category That Allows You To Handle Events Using Blocks

  •  
  •  
  •  
  •  
  •  

I previously mentioned a library that adds many different block based events to several UIControl objects.

Here’s a UIControl category from Andy Lavoy called ALActionBlocks that allows you to easily use blocks for UIControl events where you would normally supply an @selector method.

As shown in the readme for ALActionBlocks you can add a block to a UIControl with:

// Assuming you have a UIButton named 'button'
[button handleControlEvents:UIControlEventTouchUpInside withBlock:^() {
NSLog(@"button pressed: %@", [button titleForState:UIControlStateNormal]);
}];

You can then remove the blocks with:

[button removeActionBlocksForControlEvents:UIControlEventTouchUpInside];

You can find ALActionBlocks on Github here.

You can read this answer on Stackoverflow that explains the technique used to pass a block for the @selector used by the UIControl.


  •  
  •  
  •  
  •  
  •  

Submit A Resource

Have you created a useful tutorial, library or tool for iOS development that you would like to get in front of our 300,000+ monthly page views from iOS developers?

You can submit the url here.

The resources we feel will appeal to our readers the most will be posted on the front page.

Comments