3

I am trying to disable UIMenuItems in PDFKit. I have implemented

override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
    return false
}

But MenuItems Copy and Select All are still active. The main reason I want to disable them is because Select All causes fatal memory errors on larger pdf documents.

malloc: can't allocate region

I have submitted a bug report, but in the meantime I need to disable the menu item.

Note: if pdfDocument.string is large enough, any of the below calls will cause a crash.

  1. pdfView.selectAll()
  2. UIMenuController.selectAll
  3. let string = pdfDocument.string
hidden-username
  • 2,610
  • 3
  • 14
  • 19

1 Answers1

2

I needed to override canPerformAction on the actual PDFView. I was doing it in my VC.

class MyPDFView: PDFView {
    override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
        return false
    }
}
hidden-username
  • 2,610
  • 3
  • 14
  • 19