Xcode 6.1 cannot drag connection to a property from XIB - uilabel

I've just started with Xcode and I'm having a certain difficulty. I've placed a label on the canvas, declared property in viewcontroller.m, and now I'm trying to draw a connection into it, but it doesn't seem to exist. What am I doing wrong ?
I've added a screenshot - the property is not on the list for some reason, as you can see.
Using Xcode 6.1!
http://i.imgur.com/xYfoCnh.png

Select your view in your xib file and then click on File's Owner here:
With File's Owner selected, then open the identity inspector and make sure the class of File's Owner is ViewController like so:
Once you set the class of File's Owner to ViewController, you should see the UILabel property appear in the Connections Inspector for File's Owner.
Also, just for reference, the File's Owner for a view in a Xib file typically refers to the view controller (the view controller owns its view).

Related

Xcode: NSCollectionViewItem does not have an outlet named imageView or textField

I would like to link an imageView and a textField in my xib grafical user interface to the belonging Outlets from the NSCollectionViewItem (which is an element from the application kit). But while linking the bindings following message pops up:
"Xcode cannont find a Key Value Coding compliant property named #property (assign) IBOutlet NSImageView *imageView NS_AVAILABLE_MAC(10_7); in the class NSCollectionViewItem."
So, for me it is not possible to connect these objects. Therefore I don't get any Referencing Outlets for the Text Field or the Image View.
In an another xib the same bindings exist already. But they are marked with a white exclamation point and also show up a strange message: "NSCollectionViewItem does not have an outlet named imageView."
Does anyone knows how to solve the problem? Would be great.
I just tested this and can confirm, regardless of the NIB's deployment target. It seems like an Xcode bug.
I created a custom subclass of NSCollectionViewItem with no actual customizations. I set the class of the collection view item in the NIB to my custom subclass and the outlets were suddenly available. I then set the class back and they were still available. I connected one and built and got no warnings or errors.

this class is not key value coding-compliant for the key view

i'm beginner with xcode and having some problems.Everything started when i created a xib file.
I created xib file and connected to the View Controller.After that it crashed with error:"loaded the "Main" nib but the view outlet was not set."
Then i right-clicked to the File's owner icon on the left menu and drag it View icon below.There is appeared a menu Outlets.And i clicked view.
I run again and this time another error appeared:"this class is not key value coding-compliant for the key view."
I searched a lot on the net about this crash but none of them worked.Can anyone help me about this file's owner and xib stuff?
Check your outlets in nib file. Then double check them. Then check if you have properly synthesized all of your properties. Then check if your file owner object in xib is set to the proper UIViewController. Then check if you have renamed any properties in your .h/.m file after setting their outlets in XIB.
Key value coding-compliant error usually occurs when you set the outlet of an object to a property that does not exist in .h/.m file.

What's meant by File's Owner exactly?

What is meant by "File's Owner"? The XIB interface says it's UIApplication, but why is it named so? Which file does it own? I understand MVC to some extent, but I never heard of "File's Owner". What does it have to do with the controller of the application?
File's Owner is a proxy for the object that's specified as the owner when the .xib is loaded. Usually, it's the object that's actually loading the .xib. In any case, it's important to realize that File's Owner represents some object that's external to the objects in the .xib file, and as such it's basically the way that objects inside the .xib are connected to something outside the .xib and vice versa.
This all has very little to do with MVC and a lot to do with how Interface Builder works. Typically, you add IBOutlet properties and IBAction methods to the object that will load a .xib (such as an application delegate or a view controller). Then, using IB, you connect objects inside the .xib to the File's Owner proxy, and you set File's Owner as the target of your controls (choosing the appropriate action for the control).

NSViewController and bindings

In my application I have a single nib file. The File's Owner is a NSViewController and insider there is just a vertical slider that I want to bind to a property in one of my classes. (I don't have any other nib files since it is a status bar application, so I don't have a window). The nib is loaded runtime to create a custom view for a NSMenuItem.
The problem is that I want to use an object controller to do the binding but I'm not sure what is the content of the object controller. How can I access from the nib to an arbitrary class in my project?
In the examples I have seen, usually the object controller uses the File's Owner to access the class (and the property for the binding) setting the Content Object binding to the File's Owner. But in my case from the File's Owner I do not have access to the class.
Any pointer?
Ok this works for me. It is enough subclassing NSViewController and sets the new subclass as the File's Owner. Now it is possible to use a Controller Object to bind through the File's Owner.
If you use XCode 4 you can Control-drag from the slider to the .h file (AppController.h?), and you will get the option to generate an outlet or an action. If you want to create an action, caused by sliding the slider, you should select action. The generated method will be called whenever the slider is changed. If you want the slider value to react to an event (or a changed instance variable in your program), set it to 'outlet'.
Hope that helps, let me know if you were really looking for something else :-)

Loading an external NIB, how do I set the view property?

If I am loading a view from another NIB, how do I set the File's Owner view property? IB is not letting me hook it up to my View Controller which is loading the external NIB.
My NIB looks like this:
File's Owner - Identity is set to LBRootViewController
First Responder
LBTableViewController - Identity is set to LBTableViewController, NIB Name is LBTableViewController
You can't set the File Owner to a view controller defined in another nib because you can't set outlets across nibs. Each view controller has to be the File Owner of its own nib.
No nib should have two controllers that are active at one time. The setup where you have a root controller in a nav does not actually have two controllers but instead causes the root controller to load the second controller nib at runtime.
It looks like you should have two nibs here: LBRootViewController.xib and LBTableViewController.xib. The File Owner of each nib is an instance of the classes the nibs are named for. You can create an outlet in the LBRootViewController class that points to an instance of LBTableViewController. When LBRootViewController.xib loads it does not trigger the loading of LBTableViewController.xib until the attribute serving as the outlet is accessed.
Select the File's Owner proxy (in the NIB window) and switch to the identity tab in the inspector palette (the far-right tab with the circle-i icon). Set the Class field to NSViewController (or whatever your view controller subclass is, if any). You should now be able to drag your outlet!