Re: Nested Components vs Custom View
Re: Nested Components vs Custom View
- Subject: Re: Nested Components vs Custom View
- From: "M. Uli Kusterer" <email@hidden>
- Date: Fri, 5 Nov 2004 00:45:56 +0100
At 3:19 Uhr -0800 02.11.2004, Daniel Todd Currie wrote:
file://Developer/Examples/AppKit/DragNDropOutlineView/ImageAndTextCell.m
This custom cell is composed of an image cell and a text cell; you
can make them whatever size you want, and can orient them however
you want. You could have it made up of 20 text cells, if you want.
This is the basic implementation used in Finder.app for files with
icons.
Actually, it isn't. Finder.app is a Carbon PowerPlant application,
AFAIK. But apart from that, Daniel is completely right. A custom view
containing NSCells would be the recommended approach. Though there
are no cells for some controls, e.g. for the progress bar.
On 2004 Nov 02, at 03:01, Alexander F. Hartner wrote:
1.) To construct a controll by nesting various component inside each
other, like one would do using Java Swing. Having a Java back ground this
seems practical, but I don't know how to apply this in cocoa.
2.) To construct a custom view. I think this might be the preferred Cocoa
approach, yet I haven't found any examples of controlls being dynamically
added to a view.
It's very easy to create an NSView with various other views inside
it.Simply create them using e.g. [[NSTextField alloc] initWithFrame:
aRect]. You'll immediately want to autorelease that, so you don't
accidentally leak it. Then use addToSuperview: or addSubview: to
embed the created views in the superview you want to have them in.
Whether you do that from inside a function or in your own NSView
superclass (the latter would be better OOP and would also let you
write accessors for changing attributes of the subviews, so you can
treat it as one homogeneous view).
Another approach would be to create a NIB file, drag a "Custom View"
from the palette into the file's window (i.e. to create a top-level
NSView without a window around it) and to then use the NSNibLoading
stuff to instantiate the views. The "Custom View" is a simple NSView
by default, but you can of course make it your subclass, which would
give you the same advantage as above, but you can use IB to set up
the subviews instead of having to figure out the measurements in
code. It would also make localization easier.
--
Cheers,
M. Uli Kusterer
------------------------------------------------------------
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden