Skip to content

Instantly share code, notes, and snippets.

@rummelonp
Created January 23, 2011 04:12
Show Gist options
  • Save rummelonp/791807 to your computer and use it in GitHub Desktop.
Save rummelonp/791807 to your computer and use it in GitHub Desktop.
Objective-Cのクロージャ
// Make button block.
UIBarButtonItem* (^buttonWithTitle)(NSString*, SEL) = ^(NSString* title, SEL action)
{
UIBarButtonItem* button = [UIBarButtonItem alloc];
[button initWithTitle:title
style:UIBarButtonItemStyleBordered
target:self
action:action];
[button setWidth:65.0f];
[button autorelease];
return button;
};
// Make buttons.
UIBarButtonItem* some1Button = buttonWithTitle(@"some1", @selector(onClickSome1:));
UIBarButtonItem* some2Button = buttonWithTitle(@"some2", @selector(onClickSome2:));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment