我在其中使用了 PSPDKIT,我尝试调用此函数来显示我的 pdf 文件,但它一直循环我的文件。
class PDFViewController: PSPDFViewController {
override func viewDidLoad() {
super.viewDidLoad()
delegate = self
processorExample()
uploadfile()
}
func uploadfile()
{
let fileURL = Bundle.main.bundleURL.appendingPathComponent("Exhibit-A-SAMPLE-CONTRACT.pdf")
let writableURL = copyFileURLToDocumentFolder(fileURL)
let document = PSPDFDocument(url: fileURL)
let configuration = PSPDFConfiguration { builder in
builder.thumbnailBarMode = .scrollable
}
let pdfController = PDFViewController(document: document, configuration: configuration)
present(UINavigationController(rootViewController: pdfController), animated: true, completion:nil)
}
我希望它只会调用该函数一次,但它会一直调用该函数。
最佳答案
- 您的第一个
PDFViewController
加载 - 调用其
viewDidLoad()
函数 viewDidLoad()
调用uploadFile()
uploadFile()
使用第二个PDFViewController
调用present(_:animated:completion:)
。- 当第二个
PDFViewController
出现时,它会调用其viewDidLoad()
方法。 viewDidLoad()
方法调用uploadFile()
- ...
关于swift - 我可以知道代码中有什么问题吗,因为它不断一次又一次地调用该函数并导致无限循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57169352/