2014-08-27 55 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; 
} 
相關問題