Created
April 23, 2012 04:37
-
-
Save joshdholtz/2468899 to your computer and use it in GitHub Desktop.
iOS - UIButton+Block
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
[button setAction:kUIButtonBlockTouchUpInside withBlock:^{ | |
NSString* launchUrl = @"http://joshholtz.com"; | |
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: launchUrl]]; | |
}]; | |
.. |
You only updated ONE of the missing "block copy" statemetns above. The UIButton+Block.m is broken.
Wouldn't it cause a retain cycle if you use self
in the block implementation ?
@implementation ViewController
//...
[[self button] addAcction:kUIButtonBlockTouchUpInside withBlock:^{
[self doSomething];
}]
//...
@end
I'm asking because I'm trying to do something like this, and hate for the consumer of the control to always do :
__weak __typeof(self) weakSelf = self;
[[self button] addAcction:kUIButtonBlockTouchUpInside withBlock:^{
[weakSelf doSomething];
}]
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I love this simple extension.
It's better to change the import path
#import "/usr/include/objc/runtime.h"
into#import <objc/runtime.h>
in order to prevent build failure in Xcode5.