I have myController.h and myController.m defined, and proceeded to create a myController.xib with the Wizard. I can't, however, connect the controls from the xib file to the class interface. Usually when I drop the connection cross hair on the File's Owner icon, it'll show me a list of properties that have been declared as IBOutlet, but this time it's just nothing.
I thought the names of the class files and XIB file (myController) automatically binds File's Owner, but apparently that is not the case.
How can I manually bind the two?
Go to the Identity Inspector (Cmd+Option+3) and change the class to myController.
Here it is in 5.1:
I thought I would add this screenshot as it took me some time to find it!
Had the same question... XCode 4.2 enables to create a subclass of UIViewController and there you can optionally check the "with XIB for user interface" option.
New File... >> UIViewControler subclass >> "with xib..."
I found a way to do it manually... When the world is not using XIB(s) anymore...
Open the XIB or NIB file in your favourite text editor
you will find this line there...
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="MyClassName">
Change the MyClassName to the class you want to refer it to, save the file and your file's owner will be changed.
Caution: Close Xcode (To auto reload the changes) and also take a backup in case you mess up something.
I've experienced the same issue while in Xcode 4: while trying to make a connection to file's owner, the icon did not respond while dragging the connection line and hovering over file's owner. Resetting the custom class didn't work. I ended up trying quitting and restarting Xcode and only this did the trick.
If you are looking an answer for the same problema in Xcode 12.1, just set the class for the view, and restart Xcode, it will do the trick.
Related
Trying to create an AppleScript executable for MacOS 11.5 using Xcode 13 with AppleScript framework. Right out of the box (no processing on my part), the delegate icon on the IB display does not point to the default AppleScript code. This is clear since the outlet list for the icon claims that the AppDelegate does not have an outlet named theWindow whereas the AppleScript code clearly does. I've been trying for days to do a simple Hello World sort of thing and have been completely unable to connect UI elements with the "delegate", especially action elements. Am I missing some configuration step or is this a Xcode 13 bug? In examples I've seen on YouTube for creating this for this kind of simple thing the normal Xcode storyboard techniques work as expected (e.g. ctrl drag) but none of them used Xcode 13. Any insight is appreciated.screenshot of IB delegate binding
For future reference, this is starting to pop up on various forums, and appears to be a bug.
The normal signatures for creating IB outlets and action handlers is not being recognized by the Interface Editor. Existing projects - including the base Xcode templates - will build normally, although the editor shows warnings that outlets/actions don’t exist.
There isn’t much of a workaround other than creating objects programmatically or going back to an earlier version of Xcode until a fix is issued.
Update:
As mentioned in other answers and comments, the IB outlet and action handler connection bug has been fixed in Xcode 14, but the AppleScript application and Automator action templates are no longer included.
Custom templates can be created (or copied from an earlier version of Xcode from its Xcode.app/Contents/Developer/Library/Xcode/Templates/Project Templates/macOS/Other folder) and placed in a custom templates folder in your user’s Library folder at ~/Library/Developer/Xcode/Templates/. You can name this template folder whatever you want, such as "My Templates", where it will be shown in the template chooser.
Each template contains a TemplateInfo.plist file with various settings for that template - a complete tutorial is beyond the scope of this topic, but the value for the key "Identifier" in the base dictionary can be used to give your template a custom identifier, such as "com.my.cocoaApplicationAppleScript".
I am using 13.4.1 and the bug is still there.
I am wondering its its worth trying version 14 beta to see if it has been resolved
Playing around with this a little, I did find a workaround, though it's not entirely satisfactory. It amounts to editing the xib xml directly. For example, say you have button in the GUI that you'd like to reference in your script. First, create a property in the AppleScript like so:
property myButton : missing value
Then navigate to the xib file in Xcode, right-click on the xib in the file navigator and choose Open as... → Source Code (the default is "interface Builder XIB Document", which you'll want to return to later). This will show you the xml that underlies the graphical representation. First, search through the text to find the button in question. It will look something like:
<window title="Window" ...>
...
<view key="contentView" id="...">
...
<subviews>
<button ... id="xok-ud-pwL">
...
</button>
</subviews>
</view>
</window>
You want to get the id from the button, which in this case is "xok-ud-pwL". Then go back up to the top of the xml and look for the AppDelegate entry, which will look like:
<customObject id="Voe-Tx-rLC" customClass="AppDelegate"/>
You'll want to edit this so that it looks like the following:
<customObject id="Voe-Tx-rLC" customClass="AppDelegate">
<connections>
<outlet property="myButton" destination="xok-ud-pwL" id="gn6-Ea-hra"/>
</connections>
</customObject>
property should be the name of the property in the script
destination should be the id value of the button you want to connect
id should be a random and unique alphanumeric in 3-2-3 format
This will create an outlet connection between the property and the GUI element. It will even appear in the pop-up menu for the appDelegate so that you can reconnect it graphically. However, if you delete the connection in IB, Xcode will delete the entry from the xml, so you'll have to start again from scratch.
Still buggy, but...
The Release Candidate version of Xcode 14 patch it !
"Fixed an issue with outlet and action connections to AppleScript-based AppDelegates. (83373726) (FB9643535)"
But, you can't create a new project.
If you could find this old Template directory from an Xcode version < 14, you could add again the template AppleScript App.
Quit Xcode
Copy source template from version < 14 (I used v12.4):
/Applications/Xcode.app/Contents/Developer/Library/Xcode/Templates/Project Templates/macOS/Other/AppleScrip App.xctemplate
Copy to the destination folder:
/Applications/Xcode.app/Contents/Developer/Library/Xcode/Templates/Project Templates/Other/
Restart Xcode
I think Apple wants to remove AppleScript in next version of MacOS
Tested on Xcode 14 (14A309) 11 Sept 2022!
Regards
Laurent
I created a project in Xcode 6 beta 2, which initial had a storyboard. I wanted to work with separated xibs so I removed storyboard and line related to storyboard from Info.plist and added several xibs. Now the problem is that I can't connect file's owner 'view' outlet (because it's not visible) to view from xib. First thought was that I misspelled name of the file's owner custom class name (from Identity Inspector), but I didn't. Also file's owner class is a UIViewController child. I don't know that the problem can be. Did some faced this issue ?
It's probable that you need to close Xcode, clean the project and try again. I created a new project without storyboards and I did the following:
1) I created the nib file.
2) I created the UIViewController class.
3) I opened the nib and selected the File's owner tab. Then I wrote the name of the custom UIViewController class.
4) Without selecting the file's owner tab on the Placeholders left bar (make sure of this) go to Connections inspector tab and you should see the view outlet.
Simply cleaning, quitting Xcode and re-opening fixed it for me.
This is a real 'WTF?' moment for me.
I copied some classes out from another project, including copy and pasting the code and some UIBulder components. What did NOT get copied was the XIB file (I went from XIB to storyboard).
My tab / swipe recognizers aren't activating, and when I drill down the only thing I can discover that can explain it is that somehow, someway, I'm hooking up against the XIB file. (When I click on the little button next to the IBAction/IBOutlet lines in the header, it shows me both the storyboard and the xib file as connected).
I'm not referencing that file anywhere that I can find, it's just somehow magically recognized in Xcode. I don't know what to do, how to fix this.
Anyone have any ideas?
Edit: The really annoying bit is that the file doesn't appear to be in my files list when I check there, I can't just delete the reference that way. And since it's referencing the file in the original project, I can't just delete it. (Any changes made in either project cause changes in BOTH projects; their both using the same xib file for some reason). I should be able to simply delete the reference to the xib file, but I can't find the reference.
If you copy the view controller code from one project into another project you will notice a strange thing happening with the outlet. It is referencing the view from the first project without you ever connecting any outlets.
If you left click the little circle and click the reference link you will even be taken to the storyboard view in the other project. Trying to figure out how to get rid of this reference can drive you crazy.
Well, the good news is that there is really nothing for you to fix. You didn't copy over some deep, hard to find referencing link. Xcode is just getting confused because the View Controller and the outlet name are the same in both projects. Basically just ignore what that little circle says. You can close the first project and Xcode will figure things out eventually. Right click your views in the storyboard to see what referencing outlets really exist in the current project. (See my fuller answer for more details.)
No need to delete Derived Data. That doesn't solve the problem anyway. Just try opening both projects at the same time again and you will get the same strange behavior.
The way I figured this out was to separately create two new projects that had view controllers with the same name and a referencing outlet with the same name. I never copied anything but Xcode showed one was referencing the other. Like I said, ignore the little circle.
I just had the same problem. What solved it for me was to close both projects, delete the derived data from both and then reopen the destination project.
I agree, it's a crazy problem.
I'm sure that this problem could happen and I fix it deleting the content of the Derived data folder of XCode.
I just want to add the steps of how to delete those files:
Don't Delete the DerivedData folder.
Go to preferences (Command ,) > Locations Tab
On Derived Data you are going to see the path, clic the right pointing arrow (that will open that location in Finder)
Close XCode
Select all the files inside the DerivedData Folder (do NOT select parent folder) and (Command Delete) or move them to the Trash and then Empty Trash
Open the project and you are done
I hope it helps someone
unless the xib file is in the project. it should not have a link to it.
the xib file connects to the .h file. not the other way around.
You may want to remove the connections in the storyboard and re-connect them.
Also make sure that the storyboard is the UI being started and that the item on the navigation stack is actually the storyboard page. But you should be able to connect both the storyboard and the xib file to the class at the same time. You just cannot connect one IBOutlet to more than one object in a single ui component (e.g. two buttons on the storyboard cannot both be connected to #property IBOutlet UIButton *myCurrentButton you must have a separate IBOutlet for each connection. On the other hand, any number of actions can be connected to an IBAction. which is why you get (id) sender on each action.
I dont know if this is exactly what you are experiencing, but I hope that understanding helps you debug your issue.
I have a strange issues.
I have a nib file with some view inside and before yesterday all work fine for me.
Today I try to add a view in my nib file but I cannot! When I release a view inside the nib I can see an padlock overlay in the middle of XCode windows..
I changed all View "Lock" propeties in "Nothing" for all the view and the File Owner but didn't work again.
What's wrong!?
Thanks in advance.
I had the same problem and fixed it by selecting the view (or the locked element, a label in my case) and then press the Reset Locking Controls under the Interface Builder Document section in the File Inspector window.
Hope it helps.
The 'Localization Locking' Option ('Reset Locking Control')is here (Xcode 5)
Menu: Editor-> Localization Locking -> Reset Locking Control !
https://stackoverflow.com/a/19666458/1656395
In terminal use following code
sudo chown -R <UserId> <ProjectFolder>/*
I have the same problem with some xib files in different projects on different macs. IB is changing the Object IDs of some views in my xib file. I need only to double click the xib file from Xcode to open it in IB and then try to close the xib file again without changing anything and IB marks the xib file as dirty so that I have to save it again.
This drives me crazy because it will break all my localizations since they are depending on the object IDs (ibtool).
Any ideas or experiences?
Thanks
This was a bug in old versions of IB. They fixed it in, IIRC, 3.1.