• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Conceptual problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Conceptual problem


  • Subject: Re: Conceptual problem
  • From: Alex Rice <email@hidden>
  • Date: Thu, 9 Jan 2003 03:39:10 -0700

On Wednesday, January 8, 2003, at 10:01 PM, Michael Norris 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?

Any of these ways

1) connect an action of the "view" in Interface Builder to your controller object.
2) connect the data source or delegate for the "view" in Interface Builder to your controller object.

If you need to programatically call -newEntry from within the NSTableView subclass then I would use [self dataSource] or [self delegate], either of which could return the NSDocument object.

As a last resort you could add an instance variable of type (NSDocument *) to your NStableView subclass. And set it programmatically. But that's probably not the best way since dataSource and delegate are already available for that.

Alex Rice <email@hidden> | Mindlube Software | http://mindlube.com

what a waste of thumbs that are opposable
to make machines that are disposable Ani DiFranco
_______________________________________________
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.

References: 
 >Conceptual problem (From: Michael Norris <email@hidden>)

  • Prev by Date: Re: Forcing NSUserDefaults being written to disk?
  • Next by Date: Re: Aqua Human Interface and Safari
  • Previous by thread: Re: Conceptual problem
  • Next by thread: Help File Icon in Help Viewer
  • Index(es):
    • Date
    • Thread