make that dataSource (was Re: an interesting delegate design issue raised by IB...)
make that dataSource (was Re: an interesting delegate design issue raised by IB...)
- Subject: make that dataSource (was Re: an interesting delegate design issue raised by IB...)
- From: "Michael B. Johnson" <email@hidden>
- Date: Tue, 11 Sep 2001 23:12:15 -0700
Excellent! Nothing like writing stuff up and posting it to have the
obvious pointed out to you :-) I was conflating delegation and data
source, it's true.
For most of my discussion, though, the same issues I'm interested in hold
- you can replace "delegate" with "data source" for most all the
interesting bits with regard to IB.
As for the image storing issue, I'm aware of the depreciation of storing
images in nibs, and I'm still struggling with what the intent would be of
dropping images in by the user, especially when they're pasted in. I'm
hoping that the IB->PB API will happen soon, and I can do exactly what you
suggest.
Thanks for the definition clarification - my muddy thinking, but I hope
this doesn't derail anyone interesting in thinking about the particulars
of trying to have an instance of a class A that depends on a data source B
in IB and how to deal with adding data to A because it's the natural thing
to do.
Comments on that idea still welcome :-)
On Tuesday, September 11, 2001, at 10:59 PM, Enrique Zamudio wrote:
I think you're getting a little confused here. What you're trying to do
here is not a delegate but rather a data source.
A delegate is an object (any object) that responds to certain methods
that your object defines, but the idea is that if your object has a
delegate, it has to do two things:
1) ask for permission to do stuff, and
2) notify the delegate when the stuff has been done.
A delegate can implement only the methods that interest it; if your
delegate does not implement a method that you need to get permission to
do something, then you just go ahead and do it. If your delegate does
not implement a method that lets it know you've done something, then you
just don't send that message.
A data source is an object that conforms to a more formal protocol
(although the methods can be defined in an informal protocol). It has to
respond to at least some of the methods that you define for your data
source, so that you can get the objects you need.
Check out NSTableView, for example. It has both a delegate and a data
source. It needs the data source to get the rows and columns it will
display, and (optionally) to edit the values it's displaying. It uses
the delegate to ask for permission to change the selection, reorder
columns, edit a certain value, etc. and notify it when those events
happen. That's why you see methods like "tableView:shouldDoWhatever:"
and "tableView:didSomething:"; one usually returns a BOOL and the other
one is usually void. The methods receive the sender as a parameter
because many objects can have the same delegate.
I won't get into the details of the IB implementation you're trying to
do, however I would like to point out that storing images inside a nib
is not recommended anymore. Images should be stored as resources in your
project (whether it's a framework or an application). So you should be
careful when your user is adding images to the data source; perhaps you
should dig deeper into the IB framework to check if there's a way you
can pop up a panel asking the user if they want to add that image to the
project in case it's not already there (wouldn't that be pretty cool?)
but that means that you will communicate with PB from within IB.
As for the data source, you can create an abstract class of data source
for your image view, so that you define the methods you need; or you can
define a formal protocol and expect your data source to conform to that
protocol. And then you can write your own simple data source that works
from IB like you were describing.
As you know, abstract classes in ObjC don't really exist, so you
artificially define them, by raising an exception in all the methods
that you want to force your users to override (that's how I remember
that EODataSource was implemented in ObjC EOF).
Hope this helps a little,
eZL
Enrique Zamudio Lopez
Chief Software Architect
North American Software, S. A. de C. V.
Xalapa, Ver. (Mexico)
--> Michael B. Johnson, Ph.D. -- email@hidden
--> Studio Tools, Pixar Animation Studios
-->
http://xenia.media.mit.edu/~wave