Re: Request for help in getting table View to reflect fetch results
Re: Request for help in getting table View to reflect fetch results
- Subject: Re: Request for help in getting table View to reflect fetch results
- From: "Ernest Schaal" <email@hidden>
- Date: Sun, 15 Jul 2007 18:04:51 +0900
Thank you for the response. If I understand you correctly, the
controllers created automatically by control drag in 10.4 are NOT
modifiable, and one needs to create a controller from scratch. This is
important for me to know, because the end product is not product I
want to sell, the end product is the lessons learned from this process
that I am sharing with other Apple users that are contemplating
programming.
What do I tell them? It sounds like I need to tell them that while the
control drag method will give you a good binding on the quick,
changing the selection of tables created by that method can not be
done through programming.
On 7/15/07, Chris Hanson <email@hidden> wrote:
On Jul 14, 2007, at 6:46 PM, Ernest Schaal wrote:
> The next lesson is about the methods used to fetched and display
> events that are due within a given period of time. Thanks to help from
> this group I was able to do the fetch that retrieves items due within
> that period that have not been completed, but I haven't figured out
> how to apply that fetch to a table view.
The key is to invert how you're thinking about the problem. From the
sound of it, you seem to be approaching it as "how do I put data in a
table view?" But Cocoa doesn't generally work that way; it follows a
Model-View-Controller architecture, where interaction between view and
model objects is mediated by some sort of controller. So the question
should really be "How can I connect my table view through some sort of
controller to my model objects?"
There are a couple of ways you can do this, both fairly
straightforward. You can bind the NSValueBinding of each of your
table columns through an NSArrayController to the appropriate model
objects, by binding the array controller's NSContentArrayBinding to a
collection of model objects.
Or you can implement your own controller that conforms to the
NSTableDataSource informal protocol, point it at a collection of model
objects, and make it your table view's dataSource.
The latter is a very good exercise for any new Cocoa developer to go
through -- especially to create a completely generic table data source
object by following the standard "-[NSTableColumn identifier] is the
key path to use" pattern. It leads you very naturally to a bindings-
like design, completely demystifying the use of Cocoa bindings
themselves.
-- Chris
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please 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