forked from jivadevoe/UIAlertView-Blocks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUIBarButtonItem+Blocks.m
More file actions
35 lines (28 loc) · 883 Bytes
/
UIBarButtonItem+Blocks.m
File metadata and controls
35 lines (28 loc) · 883 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//
// UIBarButtonItem+Blocks.m
// Shibui
//
// Created by Kevin Vance on 8/28/14.
//
#import "UIBarButtonItem+Blocks.h"
#import <objc/runtime.h>
static NSString *RI_BUTTON_ASS_KEY = @"com.random-ideas.BUTTON";
@implementation UIBarButtonItem (Blocks)
- (id)initWithStyle:(UIBarButtonItemStyle)style item:(RIButtonItem *)item
{
if((self = [self initWithTitle:item.label style:style target:self action:@selector(buttonItemPressed:)]))
{
[self setButtonItem:item];
}
return self;
}
- (void)buttonItemPressed:(id)sender {
RIButtonItem *item = objc_getAssociatedObject(self, (__bridge const void *)RI_BUTTON_ASS_KEY);
if(item && item.action) {
item.action();
}
}
- (void)setButtonItem:(RIButtonItem *)item {
objc_setAssociatedObject(self, (__bridge const void *)RI_BUTTON_ASS_KEY, item, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
@end