2014-08-27 62 views
0

我已经创建了基于UIButtonUIBarButtonItem。我如何在事件处理程序中获得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

难道你真的确定你需要在一个的UIBarButtonItem的UIButton?用户也可以直接点击UIBarButtonItem。 – idmean 2014-08-27 12:33:21

回答

1

对于你的情况

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

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

    UIBarbuttonItem *b = self.navigationItem.leftBarButtonItem; 
}