Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you use Custom Objects in Xcode 4?

I have the same question as on this page:

In Interface Builder 3, we can drag custom object( ex. subview obj UIView ) to the stage. But in XCode 4, after we create a xib, I have trouble to reuse it except by code.
And In the "Object Library" -> "Custom Objects",it's empty.

Custom Objects in Xcode 4

But the answer given there doesn't work for me. I drag the xib file to Custom Objects list but it doesn't add anything to the list.

like image 636
2cupsOfTech Avatar asked May 18 '11 10:05

2cupsOfTech


2 Answers

Since you tagged this question as "iPhone" I am assuming you are doing iOS development. You cannot use the "Custom Objects" feature of Xcode for iOS development -- it is meant for use in apps developed for Mac.

The closest you can really get to mimicking this feature for iPhone development is to create your own custom UIView component which you can then drag between xib files.

You can also create a custom UIView subclass that has a .h/.m/.xib file. If you want to create your object programmatically, you can just do this:

NSArray *items = [[NSBundle mainBundle] loadNibNamed:@"MyClass" owner:owner options:nil];
id myView = [items objectAtIndex:0];

With regards to Mac development, the Custom Objects panel isn't actually used anymore. I would imagine that this feature will either be left out of future versions of Xcode or that Apple is still working on improving support for IB plugins. Previous versions of Xcode and Interface Builder (back when IB was it's own app) had support for interface builder plugins and the creation of custom UI elements. BWToolkit is an example of one such plugin. From the documentation:

Xcode 4 provides limited support for Interface Builder 3 plug-ins. Specifically, you can build a project with Interface Builder plug-in dependencies, but you can’t edit the nib files. When you try to open a nib file with plug-in dependencies, Xcode 4 displays a dialog suggesting that you update the file (Figure 4-3). If you agree, Xcode converts the class of custom objects built with plug-ins to the nearest AppKit class. If the conversion isn’t possible, Xcode 4 provides a detailed error message. In that case, you must remove the plug-in dependency using Interface Builder 3 before you can edit the nib file in Xcode 4.

like image 159
Michael Frederick Avatar answered Nov 16 '22 01:11

Michael Frederick


Here is your answer. You can't create custom objects past Xcode 3.x.

How to use "Custom Objects" in IB in XCode 4

If you open an Xcode 3 project with a Custom Object, it'll appear in this list.

like image 42
Jordan Avatar answered Nov 16 '22 01:11

Jordan