简体   繁体   中英

Can't create IBOutlet for UIBarButtonItem in a UIViewController

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.

I was able to create a UIBarButtonItem IBOutlet

@property (nonatomic, weak) IBOutlet UIBarButtonItem *cameraLibraryToggleButton;

故事板显示视图控制器的出口

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.
       }
 }

if u used story board then select UIBarButtonItem item and just put on the view controller.then, set IBOutlet. try this

确保您已将类(例如 .UIViewController)分配给您的故事板

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM