• 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: Loading a Document Based Application
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Loading a Document Based Application


  • Subject: Re: Loading a Document Based Application
  • From: Ivan Myrvold <email@hidden>
  • Date: Sat, 16 Jun 2001 07:32:45 +0400

Of course. When I see your reply in front of me, I can't understand what I had problem with. I think it must be something about the information overflow that sometimes blocks the clear view of what to do.

Yes, the document variable is the one I should use here.

Thanks for the example!

Ivan

On Saturday, June 16, 2001, at 07:17 AM, David P Henderson wrote:

On Friday, June 15, 2001, at 07:10 , Ivan Myrvold wrote:

I have read through all the documentation I have for a Document based application, to see if it can solve my problem. Now I think I need some help from you, on how to best tackle this:

I used the Vermont Recipes as a recipe for my application, and I have come to the part where I need to load data from file, and put the data in the TableView on my MyDocument.nib. The recipes haven't handled this yet...

Actually, it has. VR uses MySettings as its data model, MyDocument as its model controller, MyWindowController as its view controller and MyDocument.nib as its view. VR clearly shows how to get data from the model into the view. Look at the interaction between the 3 classes and the nib. A table is just another type of control like the checkboxes, buttons et al which populate VR.

[snip]
Now, my dilemma is: The data and the methods that need the data are in two different Classes. Have I in my ignorance overseen something significant here? Is this the "right" way to do this? I know there are an infinite number of ways to transfer data from file to the application, I have seen that from examples posted on this list, but I thought I would follow the wonderful Vermont recipes "way" of structuring the application.

When using the Model-View-Controller pattern, the model and the view should be fairly independent using the controller to communicate changes in state and data. In VR, the controller is further factored into a data controller and a view controller with each controller knowing how to communicate. MyDocument knows about the data model, and it knows about any view controllers for itself. MyWindowController knows about its "Document" and the views it controllers. So if you've set up proper accessors for your instance variables, you can get data contained from the model to the view like so in tableView:objectValueForTableColumn:row:

id doc = [self document]; // self is instance of MyWindowController
NSArray *dataArray = [NSArray arrayWithArray:[doc dataModel]]; // get the document's data via the accessor
id arrayItem = [dataArray objectAtIndex:row]; // Now you have the object stored at the row index in your array

Dave
--
Chaos Assembly Werks
"Nothing is too good to be true, except, perhaps, the morality of a bishop."
- Israel Zangwill


References: 
 >Re: Loading a Document Based Application (From: David P Henderson <email@hidden>)

  • Prev by Date: Re: Loading a Document Based Application
  • Next by Date: Re: NSLog
  • Previous by thread: Re: Loading a Document Based Application
  • Next by thread: Cocoa and AltiVec Optimization
  • Index(es):
    • Date
    • Thread