【问题标题】:Swift WebView signal SIGABRTSwift WebView 信号 SIGABRT
【发布时间】:2015-03-25 19:01:58
【问题描述】:

我正在尝试在 Swift 中创建一个 WebView,并在 class AppDelegate: UIResponder, UIApplicationDelegate { 行上获取错误代码“线程 1:信号 SIGABRT”

我的代码如下(变量“theURL”确实有一个真实的 URL):

    import UIKit

class ViewController: UIViewController {


    @IBOutlet var Webview: UIWebView!

    var theURL = "URL"

    func loadWebPage() {
        let theRequestURL = NSURL (string: theURL)
        let theRequest = NSURLRequest(URL: theRequestURL!)
        Webview.loadRequest(theRequest)

    }

    override func viewDidLoad() {
        super.viewDidLoad()
        loadWebPage()
        // Do any additional setup after loading the view, typically from a nib.



    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}

提前致谢!

【问题讨论】:

  • 您的 WebView 属性是否通过 Interface Builder 连接到 Web 视图?
  • 你能发布你的异常的整个堆栈跟踪吗?也尝试放置一个异常断点来推断。代码到底在哪里破坏

标签: ios swift webview


【解决方案1】:

您必须将此页面链接到您的 Main.Storyboard。您可以使用 Main.Storyboard 中的 Web 视图。

【讨论】:

    【解决方案2】:

    我知道这个问题是不久前提出的,但我只是遇到了完全相同的问题,我通过检查 main.storyboard 文件中的插座连接解决了这个问题。我从代码中删除了一个出口,但没有从 main.storyboard 中删除。单击所有视图并检查其插座连接。

    【讨论】:

      【解决方案3】:

      这将解决问题,我希望:)

      
      class ViewController: UIViewController, WKUIDelegate {
      ...
         webView.uiDelegate = self
      ...
      }
      

      请查看此链接: https://developer.apple.com/documentation/webkit/wkwebview#2560973

      【讨论】:

        【解决方案4】:

        两个原因之一 -

        • 在解包之前检查有效的 url 对象
        if let theRequestURL = NSURL (string: theURL) {
            let theRequest = NSURLRequest(URL: theRequestURL!)
            Webview.loadRequest(theRequest)
        }
        
        • 或者 Webview 没有从 storyboard 正确连接,也没有在代码中初始化

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2015-01-23
          • 1970-01-01
          • 1970-01-01
          • 2014-12-21
          • 2017-02-13
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多