Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading url on UIWebView crashes with "unrecognized selector" exception

I have built a view controller in my app whose only element is a UIWebView. I am trying to load a webpage on this uiwebview element with the following code, right after its view controller loads:

- (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];
}

String tocsUrl is a valid http string (http://192.168.1.12:3000/tocs?device=iOS).

However, the line [self.webView loadRequest:urlRequest]; is crashing the app with the following exception:

*** 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 is defined in the .h file as:

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

Any pointers on how to solve this crash will be highly appreciated.

like image 728
Luis Delgado Avatar asked Feb 10 '23 13:02

Luis Delgado


1 Answers

Check your webView, you have assigned it to UIView instead of your UIWebView. You can also remove and re add the connection to your UIWebView and Interface Builder. You can use shift+option+right click to make sure that you're choosing right controller in IB

like image 118
manman Avatar answered Feb 13 '23 06:02

manman