Customizing Lists of Annotations on iOS

PSPDFKit allows you to customize the annotation list. Here are the two approaches to customizing settings in the AnnotationTableViewController(opens in a new tab):

  1. Subclass the view controller, and then register your subclass, overrideClass(_:with:)(opens in a new tab), in the PDFConfigurationBuilder(opens in a new tab). Configure any properties in the init method of the subclass.
  2. Use the pdfViewController(_:shouldShow:options:animated:) delegate.

This is a more advanced customization because the annotation controller is packed inside a container view controller unless all other view controller options are disabled in the outline bar button:

static func PSCContainedControllerOfClass<U: UIViewController, T>(container controller: U, klass: T.Type) -> T? {
if let vc = controller as? T {
return vc
} else if let topVC = (controller as? UINavigationController)?.topViewController {
return PSCContainedControllerOfClass(container: topVC, klass: klass)
} else if let containerVC = controller as? ContainerViewController {
for viewController in containerVC.viewControllers {
if let containedVC = PSCContainedControllerOfClass(container: viewController, klass: klass) {
return containedVC
}
}
}
return nil
}
func pdfViewController(_ pdfController: PDFViewController, shouldShow controller: UIViewController, options: [String : Any]? = nil, animated: Bool) -> Bool {
let annotationController = PSCContainedControllerOfClass(container: controller, klass: AnnotationTableViewController.self)
annotationController?.showDeleteAllOption = false
// Only show ink, highlight, and stamp annotations in the annotation list.
annotationController?.visibleAnnotationTypes = [.ink, .highlight, .stamp]
return true
}