RE: Custom view - newbie stumped
RE: Custom view - newbie stumped
- Subject: RE: Custom view - newbie stumped
- From: "Kenny Millar" <email@hidden>
- Date: Tue, 25 Apr 2006 09:11:17 +0100
- Organization: Kenny Millar
Ondra,
You are dead right. I did instantiate TLView - which I now know I should not
have done. Now I know!
As for the action in the view, again you are right, the 'end product' will
not have these actions in the view, but in the controller. Originally I had
a Model, Controller and View, but couldn't get it to work, so I stripped it
all the way back to just the view and, as you saw, still could not get it to
work - until you and others pointed out where I had gone fundamentally
wrong.
Thanks to everyone who spotted what I'd done wrong and educated me!
-Kenny
.ps. I re-read the chapter in Aaron Hillegass' book and it confirmed that I
shouldn't have instantiated the view.
-----Original Message-----
From: Ondra Cada [mailto:email@hidden]
Sent: 24 April 2006 16:58
To: Kenny Millar
Cc: email@hidden
Subject: Re: Custom view - newbie stumped
Kenny,
On Apr 24, 2006, at 5:45 PM, Kenny Millar wrote:
> I added an Action to TLView, called 'addTrack'
Note please that although this would work, it is a pretty bad OO
design, for you mix controller and view. For just a test it is all
right; for real code the controller (which interprets the action)
should be separated from the view (
> I placed a button on the window and connected it to the 'addTrack'
> action.
> I placed a Custom View on the window and set it's custom class to
> be 'TLView'
This order of actions is highly suspicious: what you connected the
action to *before* adding the view (and setting it to be a TLView)?
Could it be possible you have "instantiated" TLView first, and
connected the action to that instance (the blue box in the main NIB
window, not the "Custom View" in the GUI window)?
That would explain the behaviour:
> But here's the problem, although that line of code gets called, the
> view doesn't re-draw!?!
> If I re-size the window, then as I'd expect, drawRect gets called
> again and again, but never from my 'addTrack' method.
> (I have NSLog(...) statements so I can see what's getting called
> when).
If my suspicion is right, there are *two* TLView instances in your
NIB: the former is not part of any window, but is a target of your
action. The latter is in the window, but does not receive any action.
Thus, the latter is redrawn whenever the window resizes, but
(naturally) does nothing when the button is pressed. The latter is
invalidated properly, but, since it is not part of any window, it
gets never redrawn.
---
Ondra Čada
OCSoftware: email@hidden http://www.ocs.cz
private email@hidden http://www.ocs.cz/oc
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden