How do I trigger IBAction with custom "button" based on NSView...

  • I have an NSView that has custom drawing and "hotspot". I want to be
    able to connect it to an IBAction function on my controller. However,
    in my hitTest (or mouseDown), I need to somehow trigger any attached
    action.

    Is there some sort of function that needs to be overridden?

    Thanks in advance!!!

    Nat.
  • > I have an NSView that has custom drawing and "hotspot". I want to be
    > able to connect it to an IBAction function on my controller. However,
    > in my hitTest (or mouseDown), I need to somehow trigger any attached
    > action.

      Your problem is that you're fighting the frameworks. Create your own
    custom NSButton/NSButtonCell classes, move your drawing routines to
    the cell class, and be done with it. It's *not* that much harder and
    you get all the free, wonderful things that come with a
    much-better-designed UI element than a simple NSView with an
    overridden -mouseDown: method could give you.

      Oh, and read up on the Target/Action mechanisms in Cocoa.

    --
    I.S.
  • The subject line may be a little misleading as to what I'm doing--I'm
    not really making a traditional button.

    I'm making a panel (with a clickable heading) that is part of a
    ListViewList/Accordion. In light of that, I need to alert the
    accordion controller to animate its subviews to collapse and expand
    with animation.

    On Jan 3, 2008, at 11:51 AM, I. Savant wrote:

    >> I have an NSView that has custom drawing and "hotspot". I want to be
    >> able to connect it to an IBAction function on my controller. However,
    >> in my hitTest (or mouseDown), I need to somehow trigger any attached
    >> action.
    >
    > Your problem is that you're fighting the frameworks. Create your own
    > custom NSButton/NSButtonCell classes, move your drawing routines to
    > the cell class, and be done with it. It's *not* that much harder and
    > you get all the free, wonderful things that come with a
    > much-better-designed UI element than a simple NSView with an
    > overridden -mouseDown: method could give you.
    >
    > Oh, and read up on the Target/Action mechanisms in Cocoa.
    >
    > --
    > I.S.
  • > I'm making a panel (with a clickable heading) that is part of a
    > ListViewList/Accordion. In light of that, I need to alert the
    > accordion controller to animate its subviews to collapse and expand
    > with animation.

      The concept is still the same. -mouseDown: will do, but why not just
    create a proper NSControl that happens to use a custom button cell as
    its header?

    --
    I.S.
  • Le 3 janv. 08 à 20:57, Nat Edar a écrit :

    > The subject line may be a little misleading as to what I'm doing--
    > I'm not really making a traditional button.
    >
    > I'm making a panel (with a clickable heading) that is part of a
    > ListViewList/Accordion. In light of that, I need to alert the
    > accordion controller to animate its subviews to collapse and expand
    > with animation.
    >
    > On Jan 3, 2008, at 11:51 AM, I. Savant wrote:
    >
    >>> I have an NSView that has custom drawing and "hotspot". I want to be
    >>> able to connect it to an IBAction function on my controller.
    >>> However,
    >>> in my hitTest (or mouseDown), I need to somehow trigger any attached
    >>> action.
    >>
    >> Your problem is that you're fighting the frameworks. Create your own
    >> custom NSButton/NSButtonCell classes, move your drawing routines to
    >> the cell class, and be done with it. It's *not* that much harder and
    >> you get all the free, wonderful things that come with a
    >> much-better-designed UI element than a simple NSView with an
    >> overridden -mouseDown: method could give you.
    >>
    >> Oh, and read up on the Target/Action mechanisms in Cocoa.
    >>
    >> --
    >> I.S.

    If you are using a custom view, why you do not add a subview into it,
    like an NSButton.
    Adding a small button into your custom view is easier than
    reimplenting all the button machinery.

    Regards
    Jean-Daniel
  • Haha. Yes, this is an excellent (and now obvious) point. Thank you.

    On Jan 4, 2008, at 12:33 AM, Jean-Daniel Dupas wrote:

    >
    > Le 3 janv. 08 à 20:57, Nat Edar a écrit :
    >
    >> The subject line may be a little misleading as to what I'm doing--
    >> I'm not really making a traditional button.
    >>
    >> I'm making a panel (with a clickable heading) that is part of a
    >> ListViewList/Accordion. In light of that, I need to alert the
    >> accordion controller to animate its subviews to collapse and expand
    >> with animation.
    >>
    >> On Jan 3, 2008, at 11:51 AM, I. Savant wrote:
    >>
    >>>> I have an NSView that has custom drawing and "hotspot". I want to
    >>>> be
    >>>> able to connect it to an IBAction function on my controller.
    >>>> However,
    >>>> in my hitTest (or mouseDown), I need to somehow trigger any
    >>>> attached
    >>>> action.
    >>>
    >>> Your problem is that you're fighting the frameworks. Create your own
    >>> custom NSButton/NSButtonCell classes, move your drawing routines to
    >>> the cell class, and be done with it. It's *not* that much harder and
    >>> you get all the free, wonderful things that come with a
    >>> much-better-designed UI element than a simple NSView with an
    >>> overridden -mouseDown: method could give you.
    >>>
    >>> Oh, and read up on the Target/Action mechanisms in Cocoa.
    >>>
    >>> --
    >>> I.S.
    >
    > If you are using a custom view, why you do not add a subview into
    > it, like an NSButton.
    > Adding a small button into your custom view is easier than
    > reimplenting all the button machinery.
    >
    > Regards
    > Jean-Daniel
    >
previous month january 2008 next month
MTWTFSS
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      
Go to today