Xcode and InterfaceBuilder out of sync? Check you project path!
Posted by Olaf Monien in MiscellaneousI was just testing some Delphi Prism/MonoTouch/Xcode integration stuff, which I wanted to talk about at our upcoming Developer Solutions Conference (Feb 8-10, 2011, Las Vegas), when I ran into some weird issue with Xcode and InterfaceBuilder.
Usually, when you create an iOS user interface with InterfaceBuilder, you will have to deal with IBActions and IBOutlets declared in your ViewController files. Hooking up a UIButton’s TouchUpInside event to your actual event handling method in Xcode requires you to write somthing like that in your .h/.m files:
-(IBAction) myTouchupHandler: (id) sender {
//some code here
}
InterfaceBuilder will see that declaration and you would hook it up to the actual button’s event:
You simply drag a connection from “myTouchUpHandler” in the outlet inspector to the button on the view and select “Touch Up Inside”.
Any method “marked” as return type “IBAction” will show up in this connection list on the left – usually. Same for properties marked as “IBOutlet”.
For some reason this mechanism stop working for me. InterfaceBuilder simply ignored all IBActions and IBOutlets I declared. I double checked my syntax, cleaned all targets, but still no go.
After some research on Google, I found quite some of reports from users where “Xcode Interfacbuilder sync is broken”. A common hint was to reload the corresponding class files from IB manually. This indeed worked for me, but thats not a solution. Then I got closer – I realized that the green “light” at the bottom left corner in the screen shot above (where it says “testxc.xcodeproj”) was grey. This basically means IB has lost its connection to the corresponding project. Hovering over that grey light IB says “There is no Xcode project associated …”.
Great – this happened for all new projects I created. My real projects which I work on currently seemed to work though. More Google research revealed that this happens if you open (or create) projects from Xcode. If you open a project by clicking on it in Finder, it all works – the light becomes green for the project in question.
Reports on Google suggest that this may be due to different Xcode / InterfaceBuilder versions being installed. Indeed I have Xcode 3 and Xcode 4 beta installed. So I reinstalled both and tried this in several variations, but still no go.
Interestingly the same issue in Xcode 4, eventhough InterfaceBuilder works differently here. Btw., “Cocoa with Love” has an interesting article how Xc3 and IB communicate.
Solution
Apparently Xcode and/or InterfaceBuilder have issues with certain directories. My guess is that directory names being too long confuses InterfaceBuilder. If you open the project by clicking on it in Finder, then IB probably doesn’t see the full path, but the “current” one only and doesn’t care about its length, which makes the whole thing work. If you open the project through Xcode, then it sees the whole path and stumbles at a certain point.
So I moved my project from /users/olaf/some_long_sub_dir_for_test_projects to /temp/test and everything is working and green again! In Xc3 and Xc4!





Entries (RSS)