1

Xcode 11, Swift 5.1

I'm getting a couple warnings every time I open a file and view it with QuickLook (QL). It seems to be working fine, but I'm wondering if I can get rid of the warnings.

The warnings say:

-[QLPreviewPanel setDelegate:] called while the panel has no controller - Fix this or this will raise soon.

-[QLPreviewPanel setDataSource:] called while the panel has no controller - Fix this or this will raise soon.

I set up and use QL on an NSTableCellView like this:

import Quartz

class AttachmentCell: NSTableCellView, QLPreviewPanelDataSource, QLPreviewPanelDelegate{
  var quickLookItem:URL!

  @IBAction func clickPreview(_ sender: Any) {
    guard let panel = QLPreviewPanel.shared() else{ return }
    panel.delegate = self
    panel.dataSource = self
    panel.makeKeyAndOrderFront(self)
  }
  
  func numberOfPreviewItems(in panel: QLPreviewPanel!) -> Int {
    return 1
  }

  func previewPanel(_ panel: QLPreviewPanel!, previewItemAt index: Int) -> QLPreviewItem! {
    quickLookItem = URL(fileURLWithPath: "...").appendingPathExtension(...)
    return quickLookItem as QLPreviewItem
  }
}

The clickPreview method is on an NSButton I have in my table cell. The closest thing I could find was this, but I don't see how the responder chain is involved: QLPreviewPanel in tableview with issue: "has no controller"

I also tried setting up my delegate methods on my NSViewController instead, but the same warning shows up.

Any ideas how to solve this? Or can I safely ignore it?

Community
  • 1
  • 1
Clifton Labrum
  • 13,053
  • 9
  • 65
  • 128
  • See [Can't get QuickLook to work when trying to preview files](https://stackoverflow.com/questions/57739808/cant-get-quicklook-to-work-when-trying-to-preview-files) – Willeke Oct 11 '19 at 01:17
  • Thanks for your response. If I remove `panel.delegate` and `panel.dataSource` from the `clickPreview` action and move them to the `beginPreviewPanelControl` method, Quick Look can't find the image to preview anymore: https://d.pr/i/wJtPIb – Clifton Labrum Oct 11 '19 at 18:16
  • See the linked [QuickLook consumer as a delegate from an NSViewController](https://stackoverflow.com/questions/3836782/quicklook-consumer-as-a-delegate-from-an-nsviewcontroller?rq=1) "The comments on that header, particularly on acceptsPreviewPanelControl: and the QLPreviewPanel instance method updateController, suggest that the panel's controller, when it has one, is an object that is in the responder chain. Therefore, if your controller is not becoming the panel's controller, it's because your controller isn't in the responder chain." – Willeke Oct 11 '19 at 23:38

0 Answers0