在 UIWebView 上加载 url 崩溃并出现 "unrecognized selector" 异常

Loading url on UIWebView crashes with "unrecognized selector" exception

我在我的应用程序中构建了一个视图控制器,它的唯一元素是 UIWebView。我正在尝试使用以下代码在此 uiwebview 元素上加载网页,在其视图控制器加载后立即加载:

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    NetworkHelper *networkHelper = [NetworkHelper getInstance];

    NSString *tocsUrl = [NSString stringWithFormat:@"%@%@",                         networkHelper.clientConfiguration[@"hdv_production_uri"],
                         @"/tocs?device=iOS"];
    NSURL *url = [NSURL URLWithString:tocsUrl];
    NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
    [self.webView loadRequest:urlRequest];
}

字符串 tocsUrl 是有效的 http 字符串 (http://192.168.1.12:3000/tocs?device=iOS)。

但是,行 [self.webView loadRequest:urlRequest]; 导致应用程序崩溃,但出现以下异常:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView loadRequest:]: unrecognized selector sent to instance 0x170188fd0'
*** First throw call stack:
(0x186d86530 0x197d640e4 0x186d8d5f4 0x186d8a3ac 0x186c8ec4c 0x1000b5d18 0x18b594958 0x18b594668 0x18bc881d0 0x18b88f790 0x18b8aab50 0x18b8acf68 0x18b681c4c 0x18b5c8a14 0x18b5b1d08 0x18b5c83b0 0x18b587ec8 0x186d3ed98 0x186d3bd24 0x186d3c104 0x186c691f4 0x19008b6fc 0x18b5fa10c 0x1000e0ad8 0x1983e2a08)
libc++abi.dylib: terminating with uncaught exception of type NSException

self.webView在.h文件中定义为:

@property (strong, nonatomic) IBOutlet UIWebView *webView;

任何有关如何解决此崩溃的指示将不胜感激。

检查您的 webView,您已将其分配给 UIView 而不是您的 UIWebView。您还可以删除并重新添加与 UIWebView 和 Interface Builder 的连接。您可以使用 shift+option+right click 来确保您在 IB

中选择了正确的控制器