iOS-PDF-Reader icon indicating copy to clipboard operation
iOS-PDF-Reader copied to clipboard

Adding a back button without using a nav controller?

Open jackdem opened this issue 7 years ago • 3 comments

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?

jackdem avatar Sep 14 '17 16:09 jackdem

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!

ranunez avatar Sep 18 '17 16:09 ranunez

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 :)

JorgeAGomez avatar Nov 07 '17 22:11 JorgeAGomez

Thanks for the code snippets, can you please provide a pull request?

ranunez avatar Nov 13 '17 00:11 ranunez