Re: Simple NSTableView Question - Newbie
Re: Simple NSTableView Question - Newbie
- Subject: Re: Simple NSTableView Question - Newbie
- From: Brendan Younger <email@hidden>
- Date: Wed, 15 May 2002 12:56:02 -0400
On Wednesday, May 15, 2002, at 11:22 AM, Michael George wrote:
<snip>
To expand my knowledge, I want to add a means for adding a new row into
the table. I have made a button for adding a row.
My idea is this:
Have the button send the addRow:selector message MyDataSource to add
the row.
MyDataSource will then add the row and send the noteNumberOfRowsChanged
and reloadData messages to the table view.
A minor point here. After calling -noteNumberOfRowsChanged, calling
-reloadData is redundant.
However, since the NSTableView contains MyDataSource, there is no
handle for finding out which row is selected or sending the messages to
the TableView.
Not sure what you mean by "contains". Your MyDataSource is just a data
source which means that the table view sends it messages every now and
then for information, but it doesn't retain it or in any sense "own"
it. As far as finding out the selected row, simply call -selectedRow or
-selectedRowEnumerator (both are implemented by NSTableView). If you
want your data source to have a reference to the table view, you just
have to make an instance variable and set it with -setTableView or
whatever you decide to name it. However, the object which is calling
-addRow: on your data source should probably have a reference to the
table view already, certainly it could call either one of the methods.
In fact, finding out information about view status, etc. is probably
best done by whatever object is controlling the table view (the "C" in
MVC), not by the data source. The whole reason for having a separation
between the table view and the data it's displaying is so you can have
an object which does nothing but handles data (the "M" in MVC) and be
able to put a category (if you don't know what this is yet, don't worry)
on it without having to build in any innate knowledge of how the GUI
works.
Since NSTableView doesn't have any methods for adding a row (only
columns) and there is no delegation or notification for adding a row, I
can only presume that my concept of the solution for the problem is
wrong.
No, no. In fact, you had the problem completely figured out when you
suggested calling -noteNumberOfRows changed. That's honestly all it
takes. The table view will always display exactly what your data source
says exists.
This is in the easy part of the tutorials in the book, so I'm sure it's
not a difficult problem to solve. I think I'm suffering a mental
block...
If some kind soul would point me in the right direction, I would
greatly appreciate it.
Don't mention it.
Brendan Younger
_______________________________________________
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.