Re: Global vars vs IB
Re: Global vars vs IB
- Subject: Re: Global vars vs IB
- From: Michael Carter <email@hidden>
- Date: Wed, 3 Mar 2004 08:34:22 -0800
Ryan...much better approach.
I was letting the controller handle everything directly, so it asked
the barcode model for a barcode and then set the view's image with the
result. The model and view never interacted directly. I've since added
some messaging to the view, along with it's own instance of the barcode
model. Works better I'm sure.
Thanks.
On Mar 2, 2004, at 1:40 PM, Ryan Bates wrote:
On Mar 2, 2004, at 5:01 AM, Michael Carter wrote:
In the view I am using
dragImage:at:offset:event:pasteboard:source:slideBack: in order to
allow the drag, however, I need to get to the instance of the barcode
class to obtain the EPS source I must create my NSPasteboard with.
This
instance is declared in the controller object.
How does the view know which bar code to draw? Certainly it must have
access to it in the "drawRect:" method.
I would design the BarCodeView similar to NSImageView, where the view
actually contains an instance of the model data it is drawing. That
way it can access it directly whenever it needs to. The controller
class can call the view's "setBarCode:" (or something similar) to
change which bar code the view is drawing. Then all the view has to do
is send a message to the BarCode instance variable to request the EPS
data.
If the view needs to send a message outside of itself in order to
access the bar code, that will destroy the encapsulation of the view.
In some cases it works to create a data source object which the view
requests the model from (like NSTableView) but that is generally for
displaying more complicated model objects.
On Mar 2, 2004, at 5:01 AM, Michael Carter wrote:
The way I see it so far, I can either make the barcode instance global
in scope somehow, pass the instance around willy-nilly or perhaps
instantiate the barcode class in IB and make an outlet where the view
can send a message similar to [barcode sendMeTheEPSCode]. Which would
be the best approach? Would an object calling this message get the
same
object that the controller has instantiated?
No, because you are creating an entirely new instance using Interface
Builder. Unless, of course, you point the controller's outlet to that
same instance. I generally don't like generating instances of model
objects using Interface Builder. Leave it up to the controller class
to create it then send it on to the view to display.
Ryan
On Mar 2, 2004, at 5:01 AM, Michael Carter wrote:
Hello all.
I am new to Obj-C and XCode, and am trying to work out a scope issue.
I am building an app in XCode following the Model-Controller-View
paradigm. However, I am stuck on how to access a class instance I
defined in the controller class from my view class. In this app, a
barcode is generated and it's results displayed in an NSView. What I'm
trying to do is implement the NSDraggingSource protocol to allow a
user
to drag the image of the created barcode to the Finder in order to
save
it as an EPS file.
In the view I am using
dragImage:at:offset:event:pasteboard:source:slideBack: in order to
allow the drag, however, I need to get to the instance of the barcode
class to obtain the EPS source I must create my NSPasteboard with.
This
instance is declared in the controller object.
[MyBarcode] -> [Controller] -> [MyView]
The way I see it so far, I can either make the barcode instance global
in scope somehow, pass the instance around willy-nilly or perhaps
instantiate the barcode class in IB and make an outlet where the view
can send a message similar to [barcode sendMeTheEPSCode]. Which would
be the best approach? Would an object calling this message get the
same
object that the controller has instantiated?
Thanks in advance.
______________
Mike Carter
Pilot/Programmer
Aviate.Org
_______________________________________________
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.
_______________________________________________
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.
___________________________
Mike Carter - UNIX Systems Admin
p SCV Operations
_______________________________________________
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.