Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 28 additions & 13 deletions ALActionBlocks/UIBarButtonItem+ALActionBlocks.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,48 @@ @implementation UIBarButtonItem (ALActionBlocks)


- (instancetype)initWithBarButtonSystemItem:(UIBarButtonSystemItem)systemItem block:(ALActionBlock)actionBlock {
UIBarButtonItem *barButtonItem = [[[self class] alloc] initWithBarButtonSystemItem:systemItem target:nil action:nil];
[barButtonItem setBlock:actionBlock];
return barButtonItem;

self = [self initWithBarButtonSystemItem:systemItem target:nil action:nil];
if (self) {
[self setBlock:actionBlock];
}

return self;
}


- (instancetype)initWithImage:(UIImage *)image landscapeImagePhone:(UIImage *)landscapeImagePhone style:(UIBarButtonItemStyle)style block:(ALActionBlock)actionBlock {
UIBarButtonItem *barButtonItem = [[[self class] alloc] initWithImage:image landscapeImagePhone:landscapeImagePhone style:style target:nil action:nil];
[barButtonItem setBlock:actionBlock];
return barButtonItem;

self = [self initWithImage:image landscapeImagePhone:landscapeImagePhone style:style target:nil action:nil];
if (self) {
[self setBlock:actionBlock];
}

return self;
}


- (instancetype)initWithImage:(UIImage *)image style:(UIBarButtonItemStyle)style block:(ALActionBlock)actionBlock {
UIBarButtonItem *barButtonItem = [[[self class] alloc] initWithImage:image style:style target:nil action:nil];
[barButtonItem setBlock:actionBlock];
return barButtonItem;

self = [self initWithImage:image style:style target:nil action:nil];
if (self) {
[self setBlock:actionBlock];
}

return self;
}


- (instancetype)initWithTitle:(NSString *)title style:(UIBarButtonItemStyle)style block:(ALActionBlock)actionBlock {
UIBarButtonItem *barButtonItem = [[[self class] alloc] initWithTitle:title style:style target:nil action:nil];
[barButtonItem setBlock:actionBlock];
return barButtonItem;

self = [self initWithTitle:title style:style target:nil action:nil];
if (self) {
[self setBlock:actionBlock];
}

return self;
}


- (void)setBlock:(ALActionBlock)actionBlock {
NSMutableArray *actionBlocksArray = [self actionBlocksArray];

Expand Down
9 changes: 6 additions & 3 deletions ALActionBlocks/UIGestureRecognizer+ALActionBlocks.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ @implementation UIGestureRecognizer (ALActionBlocks)


- (instancetype)initWithBlock:(ALActionBlock)actionBlock {
UIGestureRecognizer *gestureRecognizer = [[[self class] alloc] init];
[gestureRecognizer setBlock:actionBlock];
return gestureRecognizer;
self = [self init];
if (self) {
[self setBlock:actionBlock];
}

return self;
}


Expand Down
5 changes: 4 additions & 1 deletion Demo/ALActionBlocks.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
isa = PBXProject;
attributes = {
CLASSPREFIX = AL;
LastUpgradeCheck = 0460;
LastUpgradeCheck = 0700;
ORGANIZATIONNAME = "Andy LaVoy";
};
buildConfigurationList = A1AE07B8170741AC0028A95E /* Build configuration list for PBXProject "ALActionBlocks" */;
Expand Down Expand Up @@ -241,6 +241,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_OPTIMIZATION_LEVEL = 0;
Expand Down Expand Up @@ -292,6 +293,7 @@
GCC_PREFIX_HEADER = "ALActionBlocks/ALActionBlocks-Prefix.pch";
INFOPLIST_FILE = "ALActionBlocks/ALActionBlocks-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
PRODUCT_BUNDLE_IDENTIFIER = "com.andylavoy.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
TARGETED_DEVICE_FAMILY = 1;
WRAPPER_EXTENSION = app;
Expand All @@ -305,6 +307,7 @@
GCC_PREFIX_HEADER = "ALActionBlocks/ALActionBlocks-Prefix.pch";
INFOPLIST_FILE = "ALActionBlocks/ALActionBlocks-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
PRODUCT_BUNDLE_IDENTIFIER = "com.andylavoy.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
TARGETED_DEVICE_FAMILY = 1;
WRAPPER_EXTENSION = app;
Expand Down
2 changes: 1 addition & 1 deletion Demo/ALActionBlocks/ALActionBlocks-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIdentifier</key>
<string>com.andylavoy.${PRODUCT_NAME:rfc1034identifier}</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Expand Down
8 changes: 8 additions & 0 deletions Demo/ALActionBlocks/ALViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,28 @@ - (void)viewDidLoad {
self.view.backgroundColor = [UIColor whiteColor];
self.title = @"ALActionBlocks";



self.button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
self.button.frame = CGRectMake(60, 44 + 64, 200, 44);
[self.button setTitle:@"Start" forState:UIControlStateNormal];
[self.button handleControlEvents:UIControlEventTouchUpInside withBlock:^(UIButton *weakButton) {
NSLog(@"buttton pressed: %@", [weakButton titleForState:UIControlStateNormal]);

}];
[self.view addSubview:self.button];

UISwitch *aSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(120, 132 + 64, 0, 0)];
[aSwitch handleControlEvents:UIControlEventValueChanged withBlock:^(id weakControl) {
NSLog(@"value: %d", aSwitch.isOn);



}];
[self.view addSubview:aSwitch];



UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:@[@"One", @"Two", @"Three"]];
segmentedControl.frame = CGRectMake(88, 220 + 64, 143, 30);
[segmentedControl handleControlEvents:UIControlEventValueChanged withBlock:^(id weakControl) {
Expand Down