Re: Basic Question
Re: Basic Question
- Subject: Re: Basic Question
- From: Graham Cox <email@hidden>
- Date: Thu, 10 May 2012 10:10:13 +1000
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
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden