I'm trying to get into Cocoa, and for that I'm using the "Learning Cocoa with Objective-C"-book. So far so good.
In chapter 8 I have a problem. Big problem.
I have a custom view called DotView.
When drawn the view sports a big dot with a specified radius and color. Whenever there's a mouse click the dot gets redrawn at the new position. There's also a slider and when activated the dot's radius is changed to the slider setting, and the view is redrawn. Well that's the idea anyway.
The mouse clicks works fine: the mouseDown method is called and it sets the new postion and the call to setNeedsDisplay: results in a call to drawRect: Great! The dot is redrawn at the new position.
The problem is the slider. In Interface Builder it is set up to to call a setRadius: method. And it does. And the radius instance field is set correctly. But, and this is the problem, this time the call to setNeedsDisplay: has no effect (i.e. drawRect: doesn't get called) and, even worse, next time drawRect: is called (via mouseDown) the old default radius is used and not the new one set in a previous setRadius:.
It's like there's two different "versions" of the radius instance field: one used in the mouseDown/drawRect combo, and another one used in setRadius:. I can't help noticing that the stuff that works is when using the stuff inherited by NSResponder.
Any ideas?
In chapter 8 I have a problem. Big problem.
I have a custom view called DotView.
When drawn the view sports a big dot with a specified radius and color. Whenever there's a mouse click the dot gets redrawn at the new position. There's also a slider and when activated the dot's radius is changed to the slider setting, and the view is redrawn. Well that's the idea anyway.
The mouse clicks works fine: the mouseDown method is called and it sets the new postion and the call to setNeedsDisplay: results in a call to drawRect: Great! The dot is redrawn at the new position.
The problem is the slider. In Interface Builder it is set up to to call a setRadius: method. And it does. And the radius instance field is set correctly. But, and this is the problem, this time the call to setNeedsDisplay: has no effect (i.e. drawRect: doesn't get called) and, even worse, next time drawRect: is called (via mouseDown) the old default radius is used and not the new one set in a previous setRadius:.
It's like there's two different "versions" of the radius instance field: one used in the mouseDown/drawRect combo, and another one used in setRadius:. I can't help noticing that the stuff that works is when using the stuff inherited by NSResponder.
Any ideas?