ios - 需要有关 XCode : Thread 1:EXC_BAD_INSTRUCTION (WebView) 的帮助

标签 ios swift xcode

我是 XCode 的新手,我正在尝试创建一个显示 www.google.com 网站的简单 Webview

但是代码没有运行。我收到一个错误:Threat1: Signal SIGATBRT

这是我的代码:

import UIKit
import WebKit

class ViewController: UIViewController {

    @IBOutlet var WebView: WKWebView!

    override func viewDidLoad() {
        super.viewDidLoad()

        let url = URL(string: "www.google.com")
        let request = URLRequest(url: url!)

        WebView.load(request)

        // Do any additional setup after loading the view.
    }


}

Questions Update

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate { // <- The Error Pointing Here!!! -> Threat1: Signal SIGABRT



    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        return true
    }

Output Text

2020-01-16 09:58:27.127224+0200 wvApp2[6306:366786] -[__NSArrayM loadRequest:]: unrecognized selector sent to instance 0x600001f0c3c0
2020-01-16 09:59:21.186755+0200 wvApp2[6306:366786] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM loadRequest:]: unrecognized selector sent to instance 0x600001f0c3c0'
*** First throw call stack:
(
    0   CoreFoundation                      0x00007fff23c7127e __exceptionPreprocess + 350
    1   libobjc.A.dylib                     0x00007fff513fbb20 objc_exception_throw + 48
    2   CoreFoundation                      0x00007fff23c91fd4 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
    3   CoreFoundation                      0x00007fff23c75c4c ___forwarding___ + 1436
    4   CoreFoundation                      0x00007fff23c77f78 _CF_forwarding_prep_0 + 120
    5   wvApp2                              0x00000001038677ea $s6wvApp214ViewControllerC11viewDidLoadyyF + 890
    6   wvApp2                              0x0000000103867a8b $s6wvApp214ViewControllerC11viewDidLoadyyFTo + 43
    7   UIKitCore                           0x00007fff47a0ef01 -[UIViewController _sendViewDidLoadWithAppearanceProxyObjectTaggingEnabled] + 83
    8   UIKitCore                           0x00007fff47a13e5a -[UIViewController loadViewIfRequired] + 1084
    9   UIKitCore                           0x00007fff47a14277 -[UIViewController view] + 27
    10  UIKitCore                           0x00007fff480ca3cf -[UIWindow addRootViewControllerViewIfPossible] + 150
    11  UIKitCore                           0x00007fff480c9ac0 -[UIWindow _updateLayerOrderingAndSetLayerHidden:actionBlock:] + 232
    12  UIKitCore                           0x00007fff480cab43 -[UIWindow _setHidden:forced:] + 362
    13  UIKitCore                           0x00007fff480ddef1 -[UIWindow _mainQueue_makeKeyAndVisible] + 42
    14  UIKitCore                           0x00007fff482e9431 -[UIWindowScene _makeKeyAndVisibleIfNeeded] + 202
    15  UIKitCore                           0x00007fff4761d445 +[UIScene _sceneForFBSScene:create:withSession:connectionOptions:] + 1405
    16  UIKitCore                           0x00007fff4808f170 -[UIApplication _connectUISceneFromFBSScene:transitionContext:] + 1018
    17  UIKitCore                           0x00007fff4808f4b2 -[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 304
    18  UIKitCore                           0x00007fff47bfa7f5 -[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] + 361
    19  FrontBoardServices                  0x00007fff365d6165 -[FBSSceneImpl _callOutQueue_agent_didCreateWithTransitionContext:completion:] + 442
    20  FrontBoardServices                  0x00007fff365fc4d8 __86-[FBSWorkspaceScenesClient sceneID:createWithParameters:transitionContext:completion:]_block_invoke.154 + 102
    21  FrontBoardServices                  0x00007fff365e0c45 -[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:] + 220
    22  FrontBoardServices                  0x00007fff365fc169 __86-[FBSWorkspaceScenesClient sceneID:createWithParameters:transitionContext:completion:]_block_invoke + 355
    23  libdispatch.dylib                   0x0000000103b91d48 _dispatch_client_callout + 8
    24  libdispatch.dylib                   0x0000000103b94cb9 _dispatch_block_invoke_direct + 300
    25  FrontBoardServices                  0x00007fff3662237e __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 30
    26  FrontBoardServices                  0x00007fff3662206c -[FBSSerialQueue _queue_performNextIfPossible] + 441
    27  FrontBoardServices                  0x00007fff3662257b -[FBSSerialQueue _performNextFromRunLoopSource] + 22
    28  CoreFoundation                      0x00007fff23bd4471 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    29  CoreFoundation                      0x00007fff23bd439c __CFRunLoopDoSource0 + 76
    30  CoreFoundation                      0x00007fff23bd3bcc __CFRunLoopDoSources0 + 268
    31  CoreFoundation                      0x00007fff23bce87f __CFRunLoopRun + 1263
    32  CoreFoundation                      0x00007fff23bce066 CFRunLoopRunSpecific + 438
    33  GraphicsServices                    0x00007fff384c0bb0 GSEventRunModal + 65
    34  UIKitCore                           0x00007fff48092d4d UIApplicationMain + 1621
    35  wvApp2                              0x00000001038689bb main + 75
    36  libdyld.dylib                       0x00007fff5227ec25 start + 1
    37  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

这是所有输出窗口的输出文本。我认为这将有助于消除对这个问题的所有误解。此输出是从应用程序运行到异常。

Recent Issues

显示最近的问题

使用配置调试构建项目 wvApp2 的目标 wvApp2

CompileStoryboard /Users/admin/DevSource/wvApp2/wvApp2/Base.lproj/Main.storyboard (in target 'wvApp2' from project 'wvApp2')
    cd /Users/admin/DevSource/wvApp2
    export XCODE_DEVELOPER_USR_PATH=/Applications/Xcode.app/Contents/Developer/usr/bin/..
    /Applications/Xcode.app/Contents/Developer/usr/bin/ibtool --errors --warnings --notices --module wvApp2 --output-partial-info-plist /Users/admin/Library/Developer/Xcode/DerivedData/wvApp2-ehhbosgmbdwuucejiweipdfuqjzt/Build/Intermediates.noindex/wvApp2.build/Debug-iphonesimulator/wvApp2.build/Base.lproj/Main-SBPartialInfo.plist --auto-activate-custom-fonts --target-device iphone --target-device ipad --minimum-deployment-target 13.2 --output-format human-readable-text --compilation-directory /Users/admin/Library/Developer/Xcode/DerivedData/wvApp2-ehhbosgmbdwuucejiweipdfuqjzt/Build/Intermediates.noindex/wvApp2.build/Debug-iphonesimulator/wvApp2.build/Base.lproj /Users/admin/DevSource/wvApp2/wvApp2/Base.lproj/Main.storyboard

/* com.apple.ibtool.document.warnings */
/Users/admin/DevSource/wvApp2/wvApp2/Base.lproj/Main.storyboard:Bvy-8R-dSa: warning: UIWebView is deprecated since iOS 12.0 [7]

我不知道我做错了什么, 我该如何解决这个问题?欢迎任何人回答。

最佳答案

首先,您最好让变量以小写 字母开头(并以大写 键入)。这是 Swift(以及 Java、C++ 和 C 以及除 C# 之外的几乎所有其他编程语言)中的一种约定:

 @IBOutlet var webView: WKWebView!

(在 Xcode 中使用重构更改此设置,以同步 Storyboard/xib)

然后,不要使用显式展开,最好使用if let:

if let url = URL(string: "www.google.com") {
    let request = URLRequest(url: url)
    webView.load(request)
}

你的异常(exception):唯一的另一件事(除了显式 url! 展开可能会失败)可能是导出 webView 为零。你也可以检查这个:

if (webView == nil) {
    print ("Ooops")
}

如果为零,请检查 Storyboard/xib 的连接。

关于ios - 需要有关 XCode : Thread 1:EXC_BAD_INSTRUCTION (WebView) 的帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59764441/

相关文章:

ios - 如何获取 self.view 中 UICollectionViewCell 的位置?

ios - 如何在 Swift 中正确使用#selector?

ios - 如何在TableController的ImageView中正确添加图片?

ios - 应用被拒绝 : Systematic way to find (cocoapod) library that accesses privacy-sensitive data

iphone - Sqlite查询,将日期时间字段与当前日期时间进行比较

iphone - UIPopOverViewControler 中的解雇问题

swift - 如何调用swift函数

c++ - C++错误链接器命令失败,退出代码为1(使用-v查看调用)

objective-c - 将键盘快捷键发送到 Mac OS X 窗口

ios - 找不到实例方法(返回类型默认为 'id' )