• 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: More learning questions
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: More learning questions


  • Subject: Re: More learning questions
  • From: "David P. Henderson" <email@hidden>
  • Date: Sat, 4 Aug 2001 01:45:24 -0400

On Friday, August 3, 2001, at 11:07 , John Tsombakos wrote:

> MyDataSource.h
> NSMutableArray *myArray; is defined
> MyDataSource.m
> The methods to give the table it needed data
> Also, an init method to load up myArray
>
> MyTableView.m/h
> Subclass of NSTableView - I override the keyDown event to grab the
> key the user hits.
>
> In MyTableView I want to have access to the array. How/where do I
> declare/define the array so I can have access to it from MyTableView
> and MyDataSource.
>
Why? A table view is a view. Views are for display purposes; they
shouldn't be handling data that is your controller class's job. Your
data source class should be a go between for the model ie data, and the
view. But if you really must do this, your table view has access to its
data source via the dataSource outlet that connects the two objects. If
you've been a good little programmer and made accessor methods for you
data source's variables, the code in your table view would look like
this: [[self dataSource] myArray] where self is the table view and
myArray is the accessor method for getting the value of the data
source's myArray variable.

The usual way in cocoa would be to have a model, a controller and a
view; you have a controller (MyDataSource) and a view (MyTableView). In
simple cases, the controller can double as the model. The model is
responsible for managing the data, the controller is responsible for
coordinating the exchanges between the view and the model. In other
words, when the user interacts with the view, the view tells the
controller and the controller informs the model of changes; then, if
necessary, the model massages the data and informs the controller of any
changes which the controller then tells the view to display.

> I know is C I would have a 'extern int myArray[5];' in a header file
> that's included in what ever .c files I needed access to the array, and
> in one of the .c files I would have 'int myArray[5];'
>
This is Cocoa; Think Outlets and Accessors.

Dave
--
Chaos Assembly Werks
"The proper office of a friend is to side with you when you are in the
wrong. Nearly anybody will side with you when you are in the right."
- Mark Twain


References: 
 >More learning questions (From: John Tsombakos <email@hidden>)

  • Prev by Date: Thanks all
  • Next by Date: Re: Getting system info
  • Previous by thread: More learning questions
  • Next by thread: Re: More learning questions
  • Index(es):
    • Date
    • Thread