Basic Question

  • In a subclass of NSView I have implemented:

    -(void)print:(id)sender

    In IB I have connected a Print  menu item to print: in First Responder.

    My print: method is not called.

    There is only one instance of print: in the project.

    So the basic question is "why would my print: method not becalled?"

    -koko
  • As a start change (void) to (IBAction) and have IB re-ingest your .h file with the declaration in it.

    On May 9, 2012, at 12:33 PM, koko wrote:

    > In a subclass of NSView I have implemented:
    >
    > -(void)print:(id)sender
    >
    > In IB I have connected a Print  menu item to print: in First Responder.
    >
    > My print: method is not called.
    >
    > There is only one instance of print: in the project.
    >
    > So the basic question is "why would my print: method not becalled?"
    >
    > -koko

    Charlie Dickman
    <3tothe4th...>
  • On May 9, 2012, at 10:45 AM, Charlie Dickman wrote:

    > As a start change (void) to (IBAction)

    I wanted to avoid that as the documentation for NSView shows

    - (void)print:(id)sender

    as the method signature.

    -koko
  • On May 9, 2012, at 9:47 AM, koko <koko...> wrote:

    > I wanted to avoid that as the documentation for NSView shows
    >
    > - (void)print:(id)sender
    >
    > as the method signature.

    IBAction is #def'd as void -- it is just a hook for IB's benefit.

    That isn't the problem.

    More likely than not, your view isn't first responder or otherwise in the responder chain.  Thus, when the AppKit dispatches the action down the responder chain, your view isn't in the chain.

    b.bum
  • They are the exact same thing (IBAction is primarily a macro for void). In fact, unless you are trying to bind directly to the view (which you didn't seem to be) it won't make any difference at all.

    On May 9, 2012, at 9:47 AM, koko wrote:

    >
    > On May 9, 2012, at 10:45 AM, Charlie Dickman wrote:
    >
    >> As a start change (void) to (IBAction)
    >
    > I wanted to avoid that as the documentation for NSView shows
    >
    > - (void)print:(id)sender
    >
    > as the method signature.
    >
    > -koko

    --
    David Duncan
  • Just an FYI ...

    -(void)print:(id)sender

    is defined in the NSPrinting Category on NSView.

    -koko

    On May 9, 2012, at 10:45 AM, Charlie Dickman wrote:

    > As a start change (void) to (IBAction) and have IB re-ingest your .h file with the declaration in it.
    >
    > On May 9, 2012, at 12:33 PM, koko wrote:
    >
    >> In a subclass of NSView I have implemented:
    >>
    >> -(void)print:(id)sender
    >>
    >> In IB I have connected a Print  menu item to print: in First Responder.
    >>
    >> My print: method is not called.
    >>
    >> There is only one instance of print: in the project.
    >>
    >> So the basic question is "why would my print: method not becalled?"
    >>
    >> -koko
    >
    > Charlie Dickman
    > <3tothe4th...>
    >
    >
    >
    >
  • On May 9, 2012, at 10:57 AM, Bill Bumgarner wrote:

    > or otherwise in the responder chain

    I grok that ... thanks.

    -koko
  • On 9. May 2012, at 17:58, koko wrote:

    >
    > On May 9, 2012, at 10:57 AM, Bill Bumgarner wrote:
    >
    >> or otherwise in the responder chain
    >
    > I grok that ... thanks.

    what does "grok" mean?
  • On May 9, 2012, at 1:12 PM, H. Miersch wrote:

    > what does "grok" mean?

    It's a term that roughly means "to completely understand something".

    http://en.wikipedia.org/wiki/Grok

    Dave
  • On May 9, 2012, at 2:12 PM, H. Miersch wrote:

    >
    > On 9. May 2012, at 17:58, koko wrote:
    >
    >>
    >> On May 9, 2012, at 10:57 AM, Bill Bumgarner wrote:
    >>
    >>> or otherwise in the responder chain
    >>
    >> I grok that ... thanks.
    >
    > what does "grok" mean?
    >

    To grok is to intimately and completely share the same reality or line of thinking with another physical or conceptual entity. Author Robert A. Heinlein coined the term in his best-selling 1961 book Stranger in a Strange Land. In Heinlein's view, grokking is the intermingling of intelligence that necessarily affects both the observer and the observed.
  • On 10/05/2012, at 2:33 AM, koko wrote:

    > In a subclass of NSView I have implemented:
    >
    > -(void)print:(id)sender
    >
    > In IB I have connected a Print  menu item to print: in First Responder.
    >
    > My print: method is not called.
    >
    > There is only one instance of print: in the project.
    >
    > So the basic question is "why would my print: method not becalled?"

    The basic answer is because your view isn't First Responder.

    To make a view become First Responder you have to do some work - by default a view refuses First Responder, so you have to override -acceptsFirstResponder to return YES. Even then, it will only be the actual FR if it is clicked on, or the window's initialFirstResponder outlet is connected to it. If you want it to show a visual highlight when it is FR (keyboard focus ring) then you have to draw that highlight.

    To handle the Print command, you do not implement the print method. It already exists, and it's not usually overridden at that level. Instead, the view by default knows how to paginate its bounds to the paper size and will "just work" if that standard pagination is what you want. If you want something else, you override the various lower level pagination methods. This is all covered in the documentation "Printing Programming Topics for Cocoa".

    I strongly advise that you read that documentation thoroughly before hacking away at implementing print. It's far easier than it seems to implement print, but if you hack at it without a proper understanding, also very easy to completely stuff up.

    --Graham
previous month may 2012 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