Can't create IBOutlet for UIBarButtonItem in a UIViewController

↘锁芯ラ 提交于 2019-12-24 08:39:43

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!