问题
I'm trying to create an IBoutlet from a UIBarButtonItem to a UIViewController, but when ctrl+clicking and dragging to the controller, I see no indicator whatsoever, and thus it's impossible to create it. Not sure what I'm doing wrong.
Here's the screenshot, in case it could clear something up:
Thanks a lot in advance!
EDIT: I also tried to create the IBOutlet manually with @property (weak,nonatomic) IBOutlet UIBarButtonItem *barButtonItem;
and then ctrl+clicking and dragging, but same result.
回答1:
I was able to create a UIBarButtonItem IBOutlet
@property (nonatomic, weak) IBOutlet UIBarButtonItem *cameraLibraryToggleButton;
回答2:
if u used story board then select UIBarButtonItem item and just put on the view controller.then, set IBOutlet. try this
回答3:
I do not think you can create an IBOutlet for a UIBarButtonItem
... Instead create a IBOutlet for your UIToolbar
and give your UIBarButtonItem
a tag of 1. Next use this code:
for(UIBarButtonItem *button in self.toolBar.items)
{
if(button.tag == 1)
{
UIBarButtonItem *newButton = button; //Your UIBarButton
//Do whatever you want with it.
}
}
来源:https://stackoverflow.com/questions/19199382/cant-create-iboutlet-for-uibarbuttonitem-in-a-uiviewcontroller