【问题标题】:Opening a PDF file in anew web view from a button通过按钮在新的 Web 视图中打开 PDF 文件
【发布时间】:2019-12-08 12:37:57
【问题描述】:

我正在尝试在我的应用程序中打开一个 PDF 文件。但是当我点击模拟器中的按钮时,我不断收到以下错误。

2019-07-31 14:11:39.542087+1000 TJP:摄影培训[4508:715096] 接口中的未知类 _TtC24TJP_Photography_Training10AboutAppVC 生成器文件。 2019-07-31 14:11:41.020377+1000 TJP:摄影 培训[4508:715096] -[UIViewController howToUseTheAppAction:]: 无法识别的选择器发送到实例 0x7fbd6f701d60 2019-07-31 14:11:41.024444+1000 TJP:摄影培训[4508:715096] *** 由于未捕获的异常而终止应用程序 'NSInvalidArgumentException',原因:'-[UIViewController howToUseTheAppAction:]:无法识别的选择器发送到实例 0x7fbd6f701d60'

*** 第一次抛出调用堆栈:( 0 CoreFoundation 0x00000001066308db exceptionPreprocess + 331 1 libobjc.A.dylib
0x0000000104171ac5 objc_exception_throw + 48 2 核心基础
0x000000010664ec94 -[NSObject(NSObject) 不识别选择器:] + 132 3 UIKitCore 0x000000010a4ec235 -[UIResponder doesNotRecognizeSelector:] + 287 4 CoreFoundation 0x0000000106635623 ___forwarding_
+ 1443 5 CoreFoundation
0x0000000106637418 _CF_forwarding_prep_0 + 120 6 UIKitCore
0x000000010a4c1624-[UIApplication sendAction:to:from:forEvent:] + 83 7 UIKitCore 0x0000000109f168d5 -[UIControl sendAction:to:forEvent:] + 67 8 UIKitCore 0x0000000109f16bf2 -[UIControl _sendActionsForEvents:withEvent:] + 450 9 UIKitCore 0x0000000109f15ba8 -[UIControl touchesEnded:withEvent:] + 583 10 UIKitCore 0x000000010a4fa4e6 -[UIWindow _sendTouchesForEvent:] + 2547 11 UIKitCore 0x000000010a4fbbca -[UIWindow 发送事件:] + 4079 12 UIKitCore
0x000000010a4da30e -[UIApplication sendEvent:] + 356 13 UIKitCore
0x000000010a5aa2b3 dispatchPreprocessedEventFromEventQueue + 3232 14 UIKitCore 0x000000010a5acbd9 __handleEventQueueInternal + 5911 15 核心基础 0x0000000106597db1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17 16 核心基础 0x0000000106597633 __CFRunLoopDoSources0 + 243 17 CoreFoundation 0x0000000106591cef __CFRunLoopRun + 1231 18 CoreFoundation
0x00000001065914d2 CFRunLoopRunSpecific + 626 19 图形服务
0x000000010e7f42fe GSEventRunModal + 65 20 UIKitCore
0x000000010a4bffc2 UIApplicationMain + 140 21 TJP:摄影 训练 0x00000001038897db main + 75 22 libdyld.dylib
0x0000000107a3d541 开始 + 1 ) libc++abi.dylib: 终止于 NSException (lldb) 类型的未捕获异常

我遵循了一个 youtube 教程,该教程在其上的一个项目中工作,但是一旦在我正在开发的应用程序中尝试了同样的事情,它就出现了上述错误。我没有做任何不同的事情。我已经三次检查了我所有的代码和连接是否存在拼写错误。

import Foundation
import UIKit
import WebKit

class AboutAppController: UIViewController {

    let pdfTitle1 = "How to use the App"

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    @IBAction func howToUseTheAppAction(_ sender: Any) {
        if let url = Bundle.main.url(forResource: pdfTitle1, withExtension: "pdf") {
            let webView = WKWebView(frame: self.view.frame)
            let urlRequest = URLRequest(url: url)
            webView.load(urlRequest as URLRequest)

            let pdfVC = UIViewController()
            pdfVC.view.addSubview(webView)
            pdfVC.title = pdfTitle1
            self.navigationController?.pushViewController(pdfVC, animated: true)    }
    }

}

我希望 PDF 文件在新的网页视图中打开

【问题讨论】:

    标签: swift xcode pdf


    【解决方案1】:

    您可以签入您的故事板文件。我认为您可能会丢失或复制 IBOulet。即使你可以忘记删除旧的 IBoulet,它已被删除。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多