Reputation: 35050
I have created a UIBarButtonItem
based on a UIButton
. How can I get the reference of the UIBarButtonItem
(!!!) in the event handler?
UIButton *brigthnessButton = [[UIButton alloc]
initWithFrame:CGRectMake(0, 0, 32, 32)];
[brigthnessButton setImage:newImage forState:UIControlStateNormal];
forState:UIControlStateSelected];
[brigthnessButton addTarget:self action:@selector(createShortcut:)
forControlEvents:UIControlEventTouchUpInside];
shortCut = [[UIBarButtonItem alloc] initWithCustomView:brigthnessButton];
- (void)createShortcut:(UIButton *)button {
UIBarButtonItem *b = ???
}
Upvotes: 0
Views: 395
Reputation: 10424
For your case
shortCut = [[UIBarButtonItem alloc] initWithCustomView:brigthnessButton];
[self.navigationItem setLeftBarButtonItem:shortCut];//if Left button
- (void)createShortcut:(UIButton *)button {
UIBarbuttonItem *b = self.navigationItem.leftBarButtonItem;
}
Upvotes: 1