UIControls+Blocks, is the dead-simple, missing link between iOS interface controls and objective-c blocks. No more delegates and useless methods, just blocks!
There's two ways you can use all this great stuff:
- Include all the files in your project/target and add the main header:
#import "UIControls+Blocks.h"
- Or just include the controls you want like:
#import "UIButton+Blocks.h"
[myButton handleControlEvent:UIControlEventTouchDown withBlock:^{
NSLog(@"You pressed my button!");
}];
No more numberOfRowsInSection
nonsense:
[myTable setNumberOfRows:1];
Want multiple sections? No problem! Just pass an array of row values. Here's 3 sections with 2 rows each:
[myTable setNumberOfRowsInSections:@[@2,@2,@2,]];
The cellForRowAtIndexPath
alternative is handleCellCreationWithBlock
like so:
[myTable handleCellCreationWithBlock:^UITableViewCell *(UITableView *tableView, NSIndexPath *indexPath){
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
NSLog(@"Creating cell for section: %i and row: %i", [indexPath section], [indexPath row]);
cell.textLabel.text = @"";
return cell;
}];
The didSelectRowAtIndexPath
alternative is handleCellSelectionWithBlock
like so:
[myTable handleCellSelectionWithBlock:^void(UITableView *tableView, NSIndexPath *indexPath){
[tableView deselectRowAtIndexPath:indexPath animated:YES];
NSInteger row = [indexPath row];
NSLog(@"Selected cell: %i",row);
}];
The numberOfRowsInComponent
and titleForRow
alternative is setTitles
. You must pass in a two dimensional array, like so:
[myPicker setTitles:@[ @[@"Component1Row1",@"Component1Row2"], @[@"Component2Row1",@"Component2Row2"] ]];
The didSelectRow
alternative is handleSelectionWithBlock
like so:
[myPicker handleSelectionWithBlock:^void(UIPickerView *pickerView, NSInteger row, NSInteger component){
NSLog(@"You pressed row: %i in component: %i!", row, component);
}];