Re: Simple NSTableView Question - Newbie
Re: Simple NSTableView Question - Newbie
- Subject: Re: Simple NSTableView Question - Newbie
- From: Thomas Lachand-Robert <email@hidden>
- Date: Wed, 15 May 2002 20:37:05 +0200
There is a lot of questions on this list about NSTableViews and their data
sources. I believe that most people don't understand well the MVC paradigm,
and since it's particularly apparent for NSTableView, it may be useful to
explain it a little bit more (but still, refer to more complete
documentation on that).
You say that NSTableView has method for adding columns, not rows. Do you
understand why? Let me tell you, and we will see if we agree.
Let us take an example: the table view in Apple Mail, showing the list of
messages. The data here is the "database" of messages. For each message,
you have an entry containing all the header information for the message
(date, title, sender, etc.). In Cocoa, you have to store that somewhere,
for instance in a C array, in a NSDictionary, in a NSArray of NSDictionary,
in a NSArray of a custon class, whatever. This is "the model". You can
internally manipulate these data, for instance add new messages, remove
some, etc.
All these things could be done only in the Foundation framework (and plain
C), since the model DOES NOT interact with the user.
The role of the NSTableView is just to DISPLAY the message list. So it
will ask the data container "how much things do you have?", "what is the
title of the 5-th thing"? and so on. That's the view. Its role is only to
make the data apparent to the user. In the particular case of table views,
they are supposed to display a list of "records", each of them having
possbily a number of characteristics. The number of displayed
characteristics is not necessarily the same than the number of existing
one in the data cotainer. For instance, Mail doesn't display every item of
the email messages headers. This number of characteristics could possibly
change while using the view, that's why you can add/remove columns; this
has nothing to do with the data themselves: adding a column "date" for the
email list doesn't create these dates, they are here already. OTHO adding
a row means a change in the data (like when you transfer a message).
And what's the controller? Its role is to tranmit changes requested by the
user from the view (where the user interacts) to the data, and eventually
the other way if the data change by themselves (when you receive new
emails).
Undeerstanding this helps a lot for dealing with all these NS***View in
AppKit.
Thomas Lachand-Robert
********************** email@hidden
<< Et le chemin est long du projet ` la chose. >> Molihre, Tartuffe.
_______________________________________________
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.