Re: Action Cell and Matrix Madness
Re: Action Cell and Matrix Madness
- Subject: Re: Action Cell and Matrix Madness
- From: Jonathan Hess <email@hidden>
- Date: Mon, 28 Jan 2008 12:29:22 -0800
Hey Andrew -
I'm moving this discussion to cocoa-dev from xcode-users since we
aren't really talking about tools anymore.
On Jan 27, 2008, at 6:24 PM, Andrew Merenbach wrote:
Hi, Jon,
I can see that a matrix might be fairly overkill (and in the end
inefficient) for this particular purpose. I will likely, at your
suggestion, write an NSView subclass to handle the job for me,
then. But a couple of things pop up:
- Should my view be a subclass of NSControl, or higher up on the
hierarchy, such as NSResponder or simply NSView?
- Should my squares/cells in the game-of-life be NSCell subclasses?
Keep in mind that I've never written a game of life simulation. I
would just subclass NSView, and use my own subclass of NSObject to be
the tiles. NSControl, and NSCell really go hand in hand, so if you
aren't going to use one, you probably shouldn't use the other either.
I suspect that one reasonable answer would be to make an NSControl
subclass of NSCell subclasses, but I don't know whether that, too,
would be inefficient. Is that the best option?
Also, you are quite right -- when I wrote the first version of the
program I was doing it in part to learn more about Cocoa aspects
such as documents, toolbars, timers, and threads. Now, even
thoughmaybe four to six years have passed since I made the original,
I still have yet to figure out certain concepts. I appreciate your
taking the time to respond to my inquiries. :)
No Problem. Good Luck -
Jon Hess
Cheers,
Andrew
On Jan 27, 2008, at 5:33 PM, Jonathan Hess wrote:
On Jan 27, 2008, at 3:01 PM, Andrew Merenbach wrote:
Hi, Jon,
Thanks so much for your response -- it gives me quite a bit to go
on. I suppose that I'll have to weigh the benefits and costs of a
palette-based versus a code-based solution. Do you have a quick
idea as to which might be preferable in a hopefully-shipping
Leopard app at some point in the future?
Hey Andrew -
I probably wouldn't build a game of life out of a subclass of
NSMatrix unless the goal was to learn all about NSMatrix and
NSCell. I would subclass NSView instead. However, if I were set on
using NSMatrix, I would build the simple IB plugin. If you're
building a game of life, then you're probably doing it to learn
about the platform and the tools. If this is the case, learning to
author the simplest of IB plugin's is probably also a good learning
exercise.
Typically, the only downside of writing an IB plugin, is that it
introduces a plugin dependency in your nibs. However, since you're
not actually introducing a new class, if in the future, you no
longer had this plug-in, you could simply dismiss IB's missing
plugin dialog. Since there is no code dependency there wouldn't be
any real consequences.
Now that I've thought about it, if you just had a nib with an
instance of NSCell in it, you could just drag it into your library,
and you wouldn't even need a plug-in.
Here's a nib with an NSCell instance. I think you should just open
it up, and drag the cell to your library, then you can reuse it in
other nibs with no plug-in dependencies.
<cell.xib>
Good Luck -
Jon Hess
Cheers,
Andrew
On Jan 27, 2008, at 2:52 PM, Jonathan Hess wrote:
On Jan 26, 2008, at 7:40 PM, Andrew Merenbach wrote:
Hi, all,
I'm making a version of John Conway's "Game of Life" cellular
automaton that requires a grid of cells. A previous version of
my program used an NSMatrix subclass of NSCells.
Now, in IB3 on Leopard, I would like to set this up without
having to do substitutions or initializations in code (what I
had to do before).
There doesn't appear to be a way to add a cell by itself to a
view or window -- and this does indeed makes sense to me. There
also doesn't appear to be a way to change the class of an
NSButtonCell, NSTextCell, NSImageCell, et cetera in a matrix to
be a custom subclass of NSCell or NSActionCell -- this also
makes sense to me.
What doesn't make sense to me is that I can't figure out a way
to do this. I want my custom NSActionCell (or NSCell, if that
would work) subclass to be in an NSMatrix subclass. Is there no
way to do this from IB3 *without* resorting to a custom palette
plugin?
Yeah, to do what you're asking for, we would need an instance of
"NSCell" on the library. Just for a test, I whipped up an IB 3.0
plugin and didn't have to write any code to integrate a cell into
the library.
I started with the plugin project template, and deleted the
framework target, the inspector class and nib, the integration
category, and all of the files from the framework target. Then I
opened the library nib, added some text to the template object
that said "Cell" and hooked up the 'representedObject' outlet of
the library item template container to an NSObject that had its
custom class set to NSCell in the top level of the document.
After that, I could build and load my plug-in and drag vanilla
NSCell instances onto an NSMatrix.
Good Luck -
Jon Hess
Cheers,
Andrew
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden