从UIButton获取对UIBarButtonItem的引用?

时间:2014-08-27 12:30:22

标签: ios uibutton uibarbuttonitem

我已基于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 = ??? 
}

1 个答案:

答案 0 :(得分:1)

对于你的情况

shortCut = [[UIBarButtonItem alloc] initWithCustomView:brigthnessButton];
        [self.navigationItem setLeftBarButtonItem:shortCut];//if Left button

- (void)createShortcut:(UIButton *)button {

    UIBarbuttonItem *b = self.navigationItem.leftBarButtonItem;
}