Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/119.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何使用SWIFT显示多文档PDF页面的单个页面_Ios_Xcode_Pdf_Webview_Swift3 - Fatal编程技术网

Ios 如何使用SWIFT显示多文档PDF页面的单个页面

Ios 如何使用SWIFT显示多文档PDF页面的单个页面,ios,xcode,pdf,webview,swift3,Ios,Xcode,Pdf,Webview,Swift3,我想为选定的PDF文件显示一个页面,即使PDF有多个页面 因此,根据所选页码,仅显示单个PDF页面 我在写这段代码: let path = NSURL(fileURLWithPath: Bundle.main.path(forResource: "PDFName", ofType: "pdf")!) let request = NSURLRequest(url: path as URL) webView.loadRequest(request as URLRequest)

我想为选定的PDF文件显示一个页面,即使PDF有多个页面

因此,根据所选页码,仅显示单个PDF页面

我在写这段代码:

    let path = NSURL(fileURLWithPath: Bundle.main.path(forResource: "PDFName", ofType: "pdf")!)
    let request = NSURLRequest(url: path as URL)
    webView.loadRequest(request as URLRequest)
但这会显示文档的所有页面。
我只想按页码显示一页?

对于分步实施,您可以获得教程和

swift3

class ViewController:UIViewController,UIDocumentInteractionControllerDelegate
并像这样调用函数

@IBAction func btnOpenModal(_ sender: UIButton) {

  //  var button: UIButton? = (sender as? UIButton)
    let URLName: URL? = Bundle.main.url(forResource: "sample", withExtension: "pdf")
    if URLName != nil {
        // Initialize Document Interaction Controller
        let  documentInteractionController: UIDocumentInteractionController = UIDocumentInteractionController(url: URLName!)
        // Configure Document Interaction Controller
        documentInteractionController.delegate = self
        // Present Open In Menu
        documentInteractionController.presentOpenInMenu(from: sender .frame, in: self.view, animated: true)
    }
}

func documentInteractionControllerViewControllerForPreview(_ controller: UIDocumentInteractionController) -> UIViewController {

    return self
}

将UIDocumentInteractiveViewController用于您的概念我查找了这个,但没有找到解决方案。有没有一个例子或解释可以帮助我这么做。我正在处理UIPageViewController应用程序,我想添加一个PDF文件,以便所有页面都显示在一个单独的页面中。谢谢,谢谢。现在您可以显示第4页,例如PDF文件的独立ViewControllero包含20页?谢谢。你的回答帮助我完成了这个项目,效果很好。
@IBAction func btnOpenModal(_ sender: UIButton) {

  //  var button: UIButton? = (sender as? UIButton)
    let URLName: URL? = Bundle.main.url(forResource: "sample", withExtension: "pdf")
    if URLName != nil {
        // Initialize Document Interaction Controller
        let  documentInteractionController: UIDocumentInteractionController = UIDocumentInteractionController(url: URLName!)
        // Configure Document Interaction Controller
        documentInteractionController.delegate = self
        // Present Open In Menu
        documentInteractionController.presentOpenInMenu(from: sender .frame, in: self.view, animated: true)
    }
}

func documentInteractionControllerViewControllerForPreview(_ controller: UIDocumentInteractionController) -> UIViewController {

    return self
}