In my project, I want to display a popup and the view of this popup is defined in a .xib file.
To do that I use this line of code :
myPopupView = NSBundle.mainBundle().loadNibNamed("NibView", owner: self, options: nil)[0] as! UIView
Until then, it works. But the problem is when I try to add an IBOutlet. My Xib file is connected to a uiviewcollection, and I manage to create an IBOutlet on the Textfield I have in the xib file. But when now I run again my app, I have this famous message :
this class is not key value coding-compliant for the key...
So if I look on Internet, everybody says to delete the IBOutlet by clicking on the cross button in Inspector, BUT I don't want to delete it because I need this IBOutlet. So isn't it possible to have IBOutlet in a xib file ?
Thanks :)
This is very common error which means the IBOutlet you have taken in .xib is not connected to the relevant class. This kind of error I experience when i have taken a outlet and given some name like lblUserName but later i renamed that to lblFriendName, then the label in xib is still connected to lblUserName as well as lblFriendName, so at the time of compilation the xib did not find the connection for lblUserName and throws error.
So go to your xib, right click on the outlet in the xib, then you will see the cross button to disconnect. So disconnect it and connect it again.
During that also you can see the connection name, it must be wrong name or there would be two connection foe the same label in which one would be correct and another must be wrong (This case when you rename a connection as i explained)
Hope you understand, and it helps...
Happy coding ...
Related
I'm looking for a solution specifically for the issue with a Swift3 UIViewController having IBOutlets defined, but dragging actions from storyboard does not connect them to existing outlets. I can add new outlets, just with different name, and they work (still cant re-connect them later).
I see old solutions for objective-C dealing with headers and source files, but a swift is a single file per class.
Is there a way to fix "can't connect IBOutlet to swift file" issue?
but dragging actions from storyboard does not connect them to existing outlets
I've noticed this too. But it's not a difficult problem. Here's what to do:
Look carefully at the gutter next to the outlet in the code. There is a circle. Drag from that circle (no need for control-drag) to the view in the Interface Builder canvas.
I renamed a class, which happened to have an outlet connection to a label called mainLabel in a storyboard file. When I run my program, it crashes and gives me the error: "this class is not key value coding-compliant for the key mainLabel".
Other SO answers have shown this to be caused by a bad outlet connection, so I removed the connection and removed any lose ends. When trying to reconnect the label to an outlet in my code, I get the error Could not insert new outlet connection: Could not find any information for the class named CourseTableViewCell
Other SO answers have provided solutions which I have tried and haven't worked including:
Deleting the reference to the file and re-adding it
Cleaning the project
Deleting the derived data folder
deleting the label and re-adding it
Dragging from the code to storyboard rather than vice-versa
I made sure that the correct file name was listed in the identity inspector, under "Custom Class". If anybody has any other ideas, please let me know!
I can provide more information if necessary.
The following steps are what you need to do to find existing IBOutlet / IBAction from and object. Be it label, button, etc. And how to remove it.
Open Main.storyboard. The Document outline window should be visible by default on the left of your storyboard window. If not, click the icon on left of the storyboard window, next to the View As: iPhone 7.
Select the object in storyboard, it's easier to find and then select it from the document outline of the storyboard.
Open the Utility window if not yet open on the most right side. Use shortcut key Cmd-Option-0 (command-option-zero), to toggle open/close of the utility window.
Open the connection inspector by click on right arrow icon (top right most icon). Remove any unwanted IBOutlet / IBAction or any other connection you want to remove by clicking on the x icon next to the connection.
Recreate the connection. You could also drag directly from the circle next to the element in the connection window for a particular object. Else add the connection the way you have been doing for now.
As for the Class file and other coding file. You could just comment out the lines that previously have IBAction or IBOutlet. And retype the same line manually (don't cut and paste). Add back the connection from storyboard, and you should be good. Don't forget to delete the lines you commented out that you don't need anymore.
Can someone please tell me what are the steps in InterfaceBuilder to connect a set of UITextView objects to an IBOutletCollection? In my XIB file (say myfile.xib) I have a row of 8 UITextView objects. In my myfile.h file I declare an IBOutletCollection:
#property (nonatomic, retain) IBOutletCollection(UITextView) NSArray *textViews;
Now I want to connect the XIB UITextView objects to the IBOutletCollection. I tried to CTRL drag from the first UITextView in the XIB to FileOwner, but that didn't show me any IBOutlets. I tried to CTRL click (right click) on FileOwner and that popped up some little black menu. That showed my textViews outlet collection, so I tried dragging from the little circle by textViews to my UITextView objects in the XIB, but that didn't do anything. I searched google to find some sort of info on this, but I only found statements like "connect your UITextView to the IBOutletCollection in the usual way." I don't know what "the usual way" is. Please help.
Are you sure you were were dragging from the correct "little circle" to your text views, because that works fine for me.
Another way is to do it just like you connect an outlet by opening the assistant editor so you can see both the xib file and the controller's .h or .m file. Starting with no code in the controller, select the text view and control-drag from it to the area under #interface, and it should say, "Insert Outlet or Outlet Collection". When you let go, fill in the name, and then change the "connection" pull-down from "outlet" to "outlet collection". After the first one is done, control-drag from the other text views to that line of code.
Make sure the class of File's Owner is set to the class you are trying to hook up the outlet collection to. Open the Identity Inspector (Ctrl + Cmd + 3) and type the name of your class in the box. Then try hooking the outlets up again.
I am trying trying to copy all of the functionality of this example app provided by Apple called AVCam: https://developer.apple.com/library/ios/samplecode/AVCam/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010112-Intro-DontLinkElementID_2
I am 99% done with copying this code, but I just have one final problem. I have an IBOutlet statement that looks like this: #property (nonatomic, weak) IBOutlet MediaCapturePreviewView *previewView;
According to the Apple sample code, this outlet is supposed to be connected to a View object that has been placed on top of the normal/default view.
Here is a screenshot of what the Connections Inspector looks like in the Apple example:
You will notice that the IBOutlet called "previewView" has been connected to something called the "Cam Preview View".
Also, in this screenshot, you can see that I am able to select this View object by itself and that it shows a Referencing Outlet in it's connections inspector for the same IBOutlet and View Object:
My problem is that I cannot get the IBOutlet code to connect to this View Object. I have tried the normal behavior of clicking and dragging to make the connections but it just wants to create a new outlet. It will not let me connect to the outlet that I have already created.
I have been playing with this for 2 hours now and just can't get it to work like Apple's sample code.
Any help is greatly appreciated thank you.
In your .xib file, make sure that UIView class is assigned as AVCamPreviewView instead of UIView.
A few possible solutions:
Save the file with the IBOutlet you're trying to connect up (the source code, not the IB)
Clean, rebuild
Restart Xcode.
I'm getting the "not key-value coding compliant message".
I've had this several times in the past and know what it means and have always been able to resolve it, but I don't know why I'm getting it in this instance. All I've done is:
1) drag n drop a UILabel onto the main view:
2) Drag from the UILabel to view controller and get IB to insert and connect an outlet:
But when I run I get "this class is not key value coding-compliant for the key currentStatus.'"
Here's the connections:
Why is it not working, what is missing?
What you have shown is ok, check if you removed some outlet properties from your code file (.h) and forgot to remove their links from IB.