Re: NSTableView and Releasing window controllers
Re: NSTableView and Releasing window controllers
- Subject: Re: NSTableView and Releasing window controllers
- From: Michael Babin <email@hidden>
- Date: Tue, 13 Feb 2007 08:34:55 -0600
On Feb 13, 2007, at 1:02 AM, Boyd Collier wrote:
I've been trying to get a table created from a nib to work
correctly when it is "re-used" to display data from a source having
different number of rows. I've tried two approaches, but each has a
problem. If I use a single window controller that is the file's
owner in the nib that contains the table view, it works fine for
the first set of records I want to display. But if the window is
then closed and subsequently I use the same window controller to
show a table with a different number of rows, I get one of two
incorrect results. If the first table showed (for example) 2 rows
and the second table attempts to show 4 rows, only the first 2 are
shown. Or, if the first table shows 4 rows and then I close the
window containing it and open a window (controlled by the same
window controller) and attempt to show 2 rows, the application
quits when my objectValueForTableColumn method is called more often
than twice, and this is the case even though the number of records
in my data source is two and this is confirmed by the method
numberOfRowsInTableView. On the other hand, if I create a new
window controller each time I want to open a window with a table,
then the right number of rows is shown, which makes sense. However,
closing the window doesn't release the window controller, which
appears to create a memory leak, as noted by Ken Tozier (see
below). I've tried everything I can think of (e.g. reloadData) but
to no avail. Is the only solution using separate controllers for
each table, or am I overlooking something (which seems likely)?
The approach of creating a window controller subclass, making it the
file owner of the nib file for the window with the table, changing
the content of the underlying data source for the table view, and
getting the table view to update its display via reloadData should
work, so there must be a bug in your description. :-)
Is the data source for the table view your window controller class or
a separate class? Are you creating/setting a new data source when the
data changes (not necessary)? When you say numberOfRowsInTableView is
returning the number of records in the data source, are you setting
breakpoints in the numberOfRowsInTableView and the
tableView:objectValueForTableColumn:row: methods to directly observe
when they're being called and what they are returning? When you call
reloadData on the table view, you should first see a call to
numberOfRowsInTableView followed by a number of calls to
tableView:objectValueForTableColumn:row.
--
Michael Babin email@hidden
Order N Development, LLC http://www.orderndev.com/
Goldfish Aquarium for Mac: http://www.lifeglobe.com/product/index.php?
pltid=2&ref=OrderNDev
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden