0

My OS X app supports 10.9 - 10.11. I try to add some options to a printing operation by adding a print accessory view like this:

MyPrintView *printView = [[MyPrintView alloc] initWithData: [self myData]];
NSPrintOperation *printOperation = [NSPrintOperation printOperationWithView: printView];
NSPrintPanel *printPanel = [printOperation printPanel];
[printPanel addAccessoryController:[[MyPrintAccessory alloc] init]];
if (printOperation)
{
    [printOperation runOperationModalForWindow:_window delegate:_window didRunSelector:nil contextInfo:nil];
}

The accessory view is defined by a controller

@interface MyPrintAccessory : NSViewController <NSPrintPanelAccessorizing>

and a view defined in a xib file.

All works perfectly as expected in El Capitan, but in Yosemite and Mavericks while the print panel let's me choose my accessory in the pop-up button, if I choose it, nothing is displayed, the space where the accessory view should be displayed remains empty. No error messages are generated neither at compile nor at runtime.

Does anybody have a hint on how to solve this, or a hint, how to search for the cause of this behaviour?

MartinW
  • 4,966
  • 2
  • 24
  • 60

2 Answers2

1

I had the same problem. I solved it by setting the option "Use Auto Layout" to off of my print accessory view nib file.

Rohan Pillai
  • 917
  • 3
  • 17
  • 26
cometheart
  • 11
  • 1
0

My application does the same thing, and works in 10.10

There is a slight difference, but to preface: My application is an NSDocument-based application. When printing, I grab the NSPrintInfo from the NSDocument, and feed it to my print method (the code you have embedded in your question)

Looks like this:

[printView requestPrintWithPrintInfo:[doc printInfo]];

Then, instead of calling -printOperationWithView:, I call -printOperationWithView:printInfo:, and I pass the printInfo that came from the sender

From Apple's docs, you should call -printOperationWithView when:

/* Slight conveniences, for use when the application's global NSPrintInfo is appropriate. Each of these methods invokes [NSPrintInfo sharedPrintInfo] and then invokes the like-named method listed above.

To me it sounds like it should work anyways, but like I said that's seemingly the only difference in our code

A O
  • 5,516
  • 3
  • 33
  • 68
  • Have you investigated if the nib/xib is loaded correctly? Because I think before 10.10 you have to either name it explicitly via `(id)initWithNibName:(NSString *)nibName bundle:(NSBundle *)bundle` or override the initializer in your NSViewController subclass accordingly. – MartinW Apr 11 '16 at 18:03