iOS-PDF-Reader
iOS-PDF-Reader copied to clipboard
Adding a back button without using a nav controller?
I use
present(readerController, animated: true, completion: nil)
rather than a nav controller to present the view. Is it possible to have a way to add a close button to the view programmatically?
Its possible, the app should detect when its being presented in a modal, and if so, it should have some sort of close button to dismiss. Great idea!
I found a solution for this:
// Create a back button programmatically - the goBackTapped function just dismiss the viewcontroller.
let myBackButton = UIBarButtonItem(title: "Cancel", style: .done, target: self, action: #selector(self.goBackTapped(_:)))
//create the document
let document = PDFDocument(fileData: pdf_data, fileName: "contract_pdf")
//load the PDFViewController
let readerController = PDFViewController.createNew(with: document!, title: "Contract", backButton: myBackButton)
//Create a UINaviagationController and pass the readerController you just created
let targetNavigationController = UINavigationController(rootViewController: readerController)
// Present the NavitationController
self.present(targetNavigationController, animated: true, completion: nil)
Hope this help :)
Thanks for the code snippets, can you please provide a pull request?