1

I have to do a bit of processing before my app can start printing, so I do that on a thread, and once it is all done, I do

dispatch_async(dispatch_get_main_queue(),^(){
    ULIPrintableView *viewForPrinting = [[ULIPrintableView alloc] initWithData:data];
    NSPrintOperation *operation = [NSPrintOperation printOperationWithView:viewForPrinting];
    NSPrintPanel *panel = operation.printPanel;
    ULIPrintAccessoryViewController *settingsVC = [ULIPrintAccessoryViewController new];
    viewForPrinting.printOperation = operation;
    settingsVC.printView = viewForPrinting;
    [panel addAccessoryController:settingsVC];
    [operation runOperation];
});

All works fine, except that for an NSScrollView (wrapping an NSTableView) in the accessory view.

That view scrolls perfectly with a regular wired PC mouse attached to the Mac, but with an Apple trackpad (both MacBook or the external one) and two-finger scrolling, the scroll view does not update until you remove your fingers from the trackpad.

It seems as if some sort of touch-moved events were not being delivered.

If I change the last line in the block from -runOperation to -runOperationModalForWindow:delegate:didRunSelector:contextInfo: scrolling is OK again, but I don't really have a window I could show this sheet on in my use case.

If I call either runOperation method directly instead of doing my threading the scroll view scrolls fine.

uliwitness
  • 8,532
  • 36
  • 58

1 Answers1

1

So I have a workaround and a suspicion:

  • If I use -performSelectorOnMainThread:withObject: instead of dispatch_async(), the scroll view works.

  • I suspect that -performSelectorOnMainThread:withObject: doesn't use dispatch_async() under the hood, but that delivery of touch-moved events for wheel scrolling does. So when I -runOperation, I block the main dispatch queue and those events pile up "behind" my modal run loop.

Not too happy with this workaround though. What guarantees that -performSelectorOnMainThread:withObject: won't some day block the main queue as well?

uliwitness
  • 8,532
  • 36
  • 58