我已基于UIBarButtonItem
创建了UIButton
。如何在事件处理程序中获取UIBarButtonItem
(!!!)的引用?
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 = ???
}
答案 0 :(得分:1)
对于你的情况
shortCut = [[UIBarButtonItem alloc] initWithCustomView:brigthnessButton];
[self.navigationItem setLeftBarButtonItem:shortCut];//if Left button
- (void)createShortcut:(UIButton *)button {
UIBarbuttonItem *b = self.navigationItem.leftBarButtonItem;
}