我有与 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.
但是那里给出的答案对我不起作用。我将 xib 文件拖到自定义对象列表中,但它没有向列表中添加任何内容。
最佳答案
由于您将此问题标记为“iPhone”,我假设您正在进行 iOS 开发。您不能将 Xcode 的“自定义对象”功能用于 iOS 开发——它适用于为 Mac 开发的应用程序。
在 iPhone 开发中,您最接近于模仿此功能的方法是创建您自己的自定义 UIView 组件,然后您可以在 xib 文件之间拖动该组件。
您还可以创建具有 .h/.m/.xib 文件的自定义 UIView 子类。如果你想以编程方式创建你的对象,你可以这样做:
NSArray *items = [[NSBundle mainBundle] loadNibNamed:@"MyClass" owner:owner options:nil];
id myView = [items objectAtIndex:0];
关于 Mac 开发,自定义对象面板实际上不再使用了。我想这个功能要么会被排除在 Xcode 的 future 版本之外,要么 Apple 仍在努力改进对 IB 插件的支持。 Xcode 和 Interface Builder 的早期版本(当 IB 是它自己的应用程序时)支持界面构建器插件和自定义 UI 元素的创建。 BWToolkit是一个这样的插件的例子。来自文档:
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.
关于iphone - 你如何在 Xcode 4 中使用自定义对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6043579/