How to get a link to an object in a .nib file?

So far I have programmed most of the programs in the code, but it is very difficult to position the buttons in the code. I searched for a while, maybe I'm using the wrong words for my search? Anyway, I created the user interface in the nib file, it has several buttons. I loaded the .nib file into my view as follows:

NSArray* nibViews =  [[NSBundle mainBundle] loadNibNamed:@"UCMenuView" owner:self options:nil];
UIView *menuView = [nibViews objectAtIndex:0];
self.delegate = (id<UCMapviewDelegate>)delegate;
// another controller does the view switching, so I'm sending him the view  
[self.delegate pushView:menuView];

It is perfectly". But I do not understand how I get a pointer to my buttons. I know about IBOutlet, but how to connect them to elements in .nib? How to connect this @property (strong, nonatomic) IBOutlet UIButton *calendar;  to a specific button in .nib?

I tried ctrl-drag (from these small dots on the left side of @property, but this does not work (on either side). Sorry if this is a simple question, but I could not find a clear explanation

thanks for the help

+3
source share
3 answers
  • Instead, UIView *menuViewyou need to create a custom UIView Subclass for this, for example. UCMenuView. Define your properties on this regular class.
  • Open your .xib file in the editor, select the Owner of the file in the left column and set its User class in the identifier to the inspector UCMenuView.
  • Right-click the File Owner in the left column and connect your IBOutlets.
+3
source

See the Apple documentation: Creating and Connecting Outlet and Designing User Interfaces in General in Xcode .

0
source

All Articles