Re: Conceptual problem
Re: Conceptual problem
- Subject: Re: Conceptual problem
- From: Alexander Lamb <email@hidden>
- Date: Thu, 09 Jan 2003 09:54:00 +0100
Hello,
Well, I am enjoying those kind of thoughts myself, returning these days to a
pet project in Cocoa (I worked at NeXT a century ago:-).
The short answer is: each view knows its window. If a window is
participating in a document application, a window knows its controller.
Therefore, in your NSTableView subclass:
[[self window] windowController]
Will return your window controller. Obviously, to avoid warnings and other
problems, don't forget to import the interface in your .m and cast the
return of that call.
The long answer is: many things are possible. I tend to avoid as much as
possible subclassing (I don't like having classes added to my project only
because I need a few instance methods or instance variables. However,
sometimes (such as for the keyDown method) it is necessary (well, is it? I
havn't tried seeing if those key down are transmitted up the responder
chain).
Don't forget that very often you can avoid subclassing because of delegated
messages or notification. Look at the first responder object in your nib
file for example. Imagine you want to have a drawer toggle menu entry. Well,
simply add the name of the method that will toggle the drawer in the list of
methods of the class description in the nib. Connect the menu button. Now:
should you implement the "toggleDrawer:" method in a Window subclass? No,
the call, if not implemented by the various responders, will finally end up
for your window controller!
Another thing with NSTableView and am wondering myself: where should the
data source protocol be implemented? In the window controller most would
say. But then, if your window has multiple table views, it could get messy.
Rather unelegant but practical: have your NSTableView subclass act as
delegate and data source of itself (waiting to be flamed on this one:-).
Hope this helps!
Alexander
On 9.1.2003 6:01, "Michael Norris" <email@hidden> wrote:
>
Hi guys. I'm a bit of a beginner, but hope you can help me with a wee
>
"Objective-C conceptual problem" I'm having in my latest Cocoa project.
>
>
My question is: how do I send a message from a "view" class to a
>
"controller" class (MVC)? (At least I think that's my question...)
>
>
Here's the scenario: I have two classes in my current project:
>
"MyDocument.m" which is the NSDocument subclass that gets instantiated
>
for each new document, and "MyTableView.m" which is an NSTableView
>
subclass created to override a keyDown event that I want to capture in
>
an NSTableView in my document window.
>
>
The MyTableView class tests for the tab key being hit in the final row
>
of the TableView, and if so, I then want to send a "newEntry" message
>
to my MyDocument class. But how do I do that, seeing as my MyTableView
>
subclass doesn't know anything about the MyDocument instantiation?
>
>
For instance: [MyDocument newEntry] is obviously wrong, as the compiler
>
complains about "factory methods". How would I get a handle to the
>
current instantiation of the NSDocument class?
>
>
Or is this a conceptual problem I'm having? Should I be sending that
>
message somewhere else?
>
>
Cheers
>
-mike
>
_______________________________________________
>
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.
_______________________________________________
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.