View Full Version : Cocoa problem - get window index by NSEvent.
Mar 12, 2009, 08:47 AM
I have a window with 5 QTMovieView in it. I am trying to return the index of the respective QTMovieview by using the NSEvent: mouseUp. With index of the QTMovieView, I mean the index I have assigned by interface builder. Is this possible?
Mar 12, 2009, 09:04 PM
Can't you subclass QTMovieView and handle the mouseUp: event there? If not, please describe what you're trying to do.
Mar 13, 2009, 04:02 AM
I have subclassed QTMovieView and overrided the mouseUp: event there. The problem however is how to get the correct QTMovieView index (I have 5 of them). For example, if i click inside QtmovieView number 1, I would like to get this index.
Mar 13, 2009, 10:42 AM
This index you're referring to isn't a real number, it's just how you perceive them visually. You need to actually define this value somewhere. Usually this is referred to as a tag, but a QTMovieView doesn't have a tag, so you need to come up with something here. Subclassing and creating a tag accessor could work, or declaring them as IBOutlets and referring to them there, etc. You also need to have the mouseUp: event call back to your controller. Usually this is done via delegates.
Mar 13, 2009, 06:54 PM
Thank you for explaining this to a newbie ;)
My QTMovieViews is already declared as IBOutlets. Is there an easy solution to refer to them from the NSEvent:mouseUp method?
Mar 14, 2009, 10:46 AM
Here is one way to do it, which makes a few assumptions about your nib.
In your QTMovieView subclass, declare an IBOutlet ivar for your controller. Then in IB, connect each view's ivar to the controller. In your controller, declare a method in the .h and implement it in the .m for handling the mouse up event, for example:
- (void)handleMovieViewClick:(QTMovieView *)sender
if (sender == movieView1)
else if (...)
Then your mouseUp: event could be:
- (void)mouseUp:(NSEvent *)event
Mar 15, 2009, 04:14 PM
That did it! Thank you so much for your help :)