Cocoa problem - get window index by NSEvent.

Discussion in 'Mac Programming' started by eivindd, Mar 12, 2009.

  1. macrumors newbie

    Joined:
    Mar 12, 2009
    #1
    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?
     
  2. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    Can't you subclass QTMovieView and handle the mouseUp: event there? If not, please describe what you're trying to do.
     
  3. thread starter macrumors newbie

    Joined:
    Mar 12, 2009
    #3
    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.
     
  4. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #4
    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.
     
  5. thread starter macrumors newbie

    Joined:
    Mar 12, 2009
    #5
    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?
     
  6. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #6
    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:
    Code:
    - (void)handleMovieViewClick:(QTMovieView *)sender
    {
        if (sender == movieView1)
            ...
        else if (...)
            ...
    }
    Then your mouseUp: event could be:
    Code:
    - (void)mouseUp:(NSEvent *)event
    {
        [controller handleMouseViewClick:self];
    }
     
  7. thread starter macrumors newbie

    Joined:
    Mar 12, 2009

Share This Page