我正在尝试在我的应用程序中打开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 CoreFoundation
  0x000000010664ec94-[NSObject(NSObject)didNotRecognizeSelector:] +
  132 3 UIKitCore 0x000000010a4ec235
  -[UIResponder didNotRecognizeSelector:] + 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
  sendEvent:] + 4079 12 UIKitCore
  0x000000010a4da30e-[UIApplication sendEvent:] + 356 13 UIKitCore
  0x000000010a5aa2b3 dispatchPreprocessedEventFromEventQueue + 3232
    14 UIKitCore 0x000000010a5acbd9
  __handleEventQueueInternal + 5911 15 CoreFoundation 0x0000000106597db1
  __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17 16 CoreFoundation 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 start + 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文件可以在新的网络视图中打开

最佳答案

您可以签入情节提要文件。我认为您可能会丢失或重复IBOutlet。即使您可以忘记删除已删除的旧IBOutlet。
swift - 通过按钮在新的Web View 中打开PDF文件-LMLPHP

09-08 05:52