0

Trying to setup printing from a custom NSTextView (which uses TextKit components). This is what I now do using a second view:

override func printView(_ sender: Any?) {
    let printTextView = MyTextView(frame: view.frame, textContainer: self.textContainer)
    let op = NSPrintOperation(view: printTextView)

    op.run()
}

So when the Print Dialog appears, it shows the correct text with attributes and layout, but the original MyTextView is suddenly empty, as if the text was moved from the view to the print view.

What am I missing here?

koen
  • 5,383
  • 7
  • 50
  • 89
  • 1
    Can text views share a `textContainer`? – Willeke Jul 30 '19 at 05:32
  • Ah, good point - let me go dig into that. Probably need to recreate the `layoutManager` and 'textStorage` as well. – koen Jul 30 '19 at 09:00
  • Alternatively, I am going to explore copying the whole view using `NSCoder` and friends. – koen Jul 30 '19 at 09:34
  • The same thing happens when printing an `NSTableView` - it disappears from its window. Maybe the original tableView (or its VC) gets deallocated when the Print Dialog appears? – koen Jul 31 '19 at 13:29
  • I don't think `NSTableView` has anything to do with `textContainer`. Ask a new question about printing a table view please. – Willeke Jul 31 '19 at 14:23
  • Yes, I understand they have nothing to do with each other. Just thinking out loud if something else could be going on since it happens with both an `NSTextView` and an `NSTableView`. I'll keep digging. – koen Jul 31 '19 at 15:03

0 Answers0