NOTE: Perhaps this question could be answered by a pure Objective-C expert as well? I work primarily in MonoTouch, but I think this problem may not be MonoTouch-specific.
Typically when the Assistant Editor in XCode won’t show my .h file, I just close everything, delete my obj directory, and rebuild all. I wait for the Indexing process to complete. But this time I really can’t get the .h file to show up, and thus I’m unable to add any new outlets to my FooViewController.
So far, I’ve tracked it down to an empty IBClassDescriber element in my FooViewController.xib
<object class="IBClassDescriber" key="IBDocument.Classes"/>
which should look something more like:
<object class="IBClassDescriber" key="IBDocument.Classes">
<array class="NSMutableArray" key="referencedPartialClassDescriptions">
<object class="IBPartialClassDescription">
<string key="className">FooViewController</string>
<string key="superclassName">UIViewController</string>
<dictionary class="NSMutableDictionary" key="outlets">
...
</dictionary>
<dictionary class="NSMutableDictionary" key="toOneOutletInfosByName">
...
</dictionary>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
<string key="minorKey">./Classes/FooViewController.h</string>
</object>
</object>
</array>
</object>
which has the link to the .h file in the minorKey of IBClassDescriptionSource.
I’ve tried cleaning my project, closing all my apps and deleting the obj and bin directories. I’ve tried renaming the file (along with the above). And other various sporadic cursing and deleting/reverting/and banging things loudly. To no avail.
Anyone know how to recover the IBClassDescriber element once it’s been emptied?
I’m going to have a look back through the file history and see when it disappeared. Maybe that’ll give me a clue.
Thanks!
CM
So this scenario came about (like other people have done) when I had renamed my
ViewControllerfile and failed to update all references to the old name. There are several places the name of the view controller needs to change, but there are really only 2 critical places that need to match to get XCode and MonoDevelop in synch. For this example, assume I had a view controller namedFooViewControllerand had renamed it toBarViewController.First, every time you launch XCode (XC), MonoDevelop (MD) creates a temporary directory named
obj/XCode/#where#starts at 0 and increments by one every time you re-launch XC. The number resets to 0 every time you restart MD. Every time you close XC and return to MD, the directory will be deleted.NOTE: the directory will NOT be deleted if you are browsing the directory from Finder or Terminal, etc.
MD creates the required
.hand.mfiles in that directory that XC expects to see. The names of these files are based on the value if theRegisterattribute inYourViewController.designer.cs. In my case, I had properly updated the.designerfile to:Now when I open the
.xibI get the dreadedNo Assistant Resultserror.At this point, my
.xibfile, when opened in the Source Code Editor of MD, showed a fullIBClassDescribersection (though improperly referencing./Classes/FooViewController.hsince I hadn’t updated it yet).What I did next was to save the
.xibfrom XC. Since XC could not find./Classes/FooViewController.h(MD was now generatingBarViewController.h), it deleted theIBClassDescribersection from the.xib, giving me an empty entityI had failed to update the
.xibproperly, now I had lost this entire section (which had numerous references that I didn’t want or know how to recreate).The key to fixing this was noticing that the
-1.CustomClassnameproperty in the.xibwas set incorrectly. Updating it to match theRegistersettingand re-saving the file resulted in XC recreating the entire
IBClassDescribersection with proper references to the.hfileSo in summary, when you’re renaming files, the places to change are:
FooViewController.cstoBarViewControllercs. Using Refactor (right click class file -> refactor -> rename) will update lots of stuff for you, including the.designerfile and any references to the class throughout your codepublic GrepViewController () : base ("BarViewController", null)which is required for loading the class at runtime.designerfile and change theRegistercall so that the link between XC and MD is maintained:[Register ("BarViewController")] partial class BarViewController.xib:BarViewController.xibBarViewController.xibin MD with source editor (right click -> open with -> Source Code Editor) and change the-1.CustomClassNamekey:<string key="-1.CustomClassName">BarViewController</string>.xibfrom MDBarViewController.xibin XC. (If you’ve got it open in MD, you’ll need to right click -> Open With -> XCode). Wait for indexing to complete, then open the Assistant Editor. Notice thatBarViewController.his (correctly) opened..xibfrom XC..xibin MD and notice thatIBClassDescribersection is fully specified, even if it was empty to start with.Ship it!
Hope this helps someone, clears up some mystery of the linkage between XC and MD, or at least reminds me what to do next time I run into this problem.
Cheers,
CM