Creating a reusable CustomView with IB
Creating a reusable CustomView with IB
- Subject: Creating a reusable CustomView with IB
- From: "Moldenhauer, Paul" <email@hidden>
- Date: Wed, 18 Sep 2002 11:24:06 -0500
Hi All,
I'm fairly new to Cocoa development and I want to do something that seems
like it should be simple to do, but I just can't seem to find any
explanation anywhere about the proper/official way to do it. The short
description of what I want to do is that I want to create a custom NSView
class in Project Builder and I want to build/layout it's contents within
Interface Builder. The reason is so that I can create a reusable custom UI
element from off-the-self IB controls.
An example might help further clarify what I'm trying to do. Take for
example a window that contains two tableviews side by side with buttons with
left and right arrows between them. The buttons with the arrows would allow
the user to move items from one list box to the other. Now suppose I had two
windows that needed this kind of functionality. I could draw the two table
views and the buttons in each window in IB and write the code to handle the
buttons' actions in each window's controller. But this duplicates code and I
have to duplicate the same interface in each window's nib file. Duplication
is generally bad, isn't it?
It seems to me a better way would be to be able to build a custom NSView in
IB, draw/layout the two table views and the buttons once in the custom view.
The create one custom NSView class that contains the outlets and actions for
the tableviews and the buttons respectively. Then create all the code that
handles the functionality in this one custom NSView class. Now I can reuse
this NSView in as many windows as I want and I only wrote the code and
designed the interface once. Also, now if I decide to change this custom
view it will cascade throughout my entire application.
The closest I've come to achieving this is by creating a custom IBPalette.
However I've had several problems with this approach. If I make changes to
the palette the change doesn't automatically cascade through all the windows
that use the item from the palette. It seems that I have to open each window
and re-add the item from the palette. Also now I'm getting a exception when
IB loads the palette and my custom view's are not displaying (the exception
says something like "[IBViewCache recache:] failed, unable to display").
Thanks for reading all that, if you made it this far. If you have any
insight into how to help me I would extremely grateful. Thanks again.
Paul Moldenhauer
email@hidden
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.