Upon rolling over or clicking on an NSView, how can I update the view so that I can change the colour and other properties of view? It's the redrawing of the view which is the key to what I need to do, I already have a subclass created.
Asked
Active
Viewed 1,881 times
6
-
How are you keeping references to your views? Are you by any chance using a collection view? – Jul 06 '11 at 00:39
1 Answers
5
Listen for mouse events and do appropriate actions inside them.
-(void)mouseEntered:(NSEvent *)theEvent {
//draw rollover
}
-(void)mouseExited:(NSEvent *)theEvent {
//draw normal
}
-(void)mouseDown:(NSEvent *)theEvent {
//draw selected
}
-(void)mouseUp:(NSEvent *)theEvent {
//draw normal
}

sudo rm -rf
- 29,408
- 19
- 102
- 161
-
@alexgray: What doesn't work? The methods aren't called? You need to make sure your window subclass conforms to the `NSWindowDelegate`. – sudo rm -rf Mar 27 '12 at 02:23
-
4-mouseDown and -mouseUp should work like expected. However, -mouseEntered and -mouseExited need trackingAreas to work. See http://stackoverflow.com/a/11190700/388412 – auco Apr 20 '13 at 14:46