How to create a reusable form using Cocoa bindings?
I want to make a user interface in which the user can edit two objects at the same time. The main window would have a vertical split view and a form on each side of the view. The problem is that the two forms are identic开发者_开发知识库al and I don't want to duplicate the view components in the interface builder. I want to create the form one time and add a reference to it in each side of the split view, each one using a different object source. I could use a NSForm, but the form is not a simple grid of outputTexts and inputText. They have a master table, and diverse kinds of inputs types, like combos, in the detail. How do I create the reusable form using the interface builder? Or how can I do it programmatically? Do I have to create a subclass of NSView and add the individual components in the code?
Thanks, Juliano
Similar to the way you create a NSWindowController subclass which manages a nib containing your window, you can create a NSViewController subclass which manages a nib containing the view, then instantiate it twice and (programmatically) add the two views to each of the subviews of the split view. See the code in this question for a (partial) example.
If you build one form in IB, you can option-drag it to the other side of the split view to create an exact copy, including bindings and connections.
精彩评论