I'm trying to do some UI changes when a user swipes to the next or previous page in the PDFView. I have it set up to use the default PageViewController. I'm adding an observer onto the PDFView and I have a selector set up for it. It crashes when I try swiping and the error message is this:
-[PDFView handlePageChangedWithNotification:] unrecognized selector sent to instance
...
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[PDFView handlePageChangedWithNotification:]: unrecognized selector to instance.
I've checked for a delegate method and didn't find anything that would help do this functionality. So, I'm assuming I have to have it named properly for this to work. Here is the code that I am using to add the observer:
// Add observer to pdfView
// This is added in viewDidAppear()
NotificationCenter.default.addObserver(pdfView, selector #selector(handlePageChange(view:)), name: .PDFViewPageChanged, object: nil)
// Selector method for observer
@objc private func handlePageChange(view: PDFView)
{
// Do some changes
}
I expect to be able to check when a new page is shown to be able to check the PDFOutline if this page is marked as a bookmark and change the bookmark button to show that it is already a bookmark. Thanks for any help you can give.
EDIT: I checked the documentation for the PDFViewPageChanged notification and it says that the notification object is the PDFView itself. It's still crashing tho but I guess that's one issue down. I changed it in the code example above to what I have now.
You're telling notification center to notify the PDFView
when the notification triggers. PDFView
doesn't implement that method. Whatever class you wrote the method in is what should be handling the notification. So:
NotificationCenter.default.addObserver(self, selector #selector(handlePageChange(view:)), name: .PDFViewPageChanged, object: nil)
Also, your notification handler method has the wrong signature. Notification center passes the notification to the method, not the actual view, so you would want it to be
@objc private func handlePageChange(notification: Notification)