How to know when an annotation got unselected

Product: PDFNet iOS pod

Product Version: 9.4.0.80508

Please give a brief summary of your issue:
Hi,

Is there any way to get notified or check when an annotation got unselected or to know if a given annotation is currently selected? I can’t find it on the documentation, only how to select and know when an annotation gets selected, but not the other way around.

Thank you :slight_smile:

Hi @lluis.morato,

Thank you for getting in touch with us about this.
The best way to do this would be to subclass the PTAnnotEdit tool by following this guide on subclassing Apryse components:
https://docs.apryse.com/documentation/ios/guides/tools/customization/#override-classes

You can then override the implementation of the deselectAnnotation method and check for the current annotation in that function.

class MyAnnotEditTool : PTAnnotEditTool
{
    override func deselectAnnotation() {
        if let annot = self.currentAnnotation {
            //
        }
        super.deselectAnnotation()
    }
}

Please let us know if that works for you.

Hi @jamie

It worked like a charm, posted a notification from there to be able to update my whole UI

class PDFTronAnnotationEditTool: PTAnnotEditTool {
    private let annotationDeselectedNotificationName = NSNotification.Name(rawValue: "AnnotationDeselectedNotificationName")

    override func deselectAnnotation() {
        if let annotationId = currentAnnotation?.annotationId {
            NotificationCenter.default.post(name: annotationDeselectedNotificationName, object: nil, userInfo: ["annotationId": annotationId])
        }
        super.deselectAnnotation()
    }
}

Thank you so much :slight_smile:

Hi @lluis.morato,

Great! We’re glad to hear that worked for you.

As always please get in touch with any other questions or issues and we will do our best to help.