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.
webViewin your xib/storyboard - it looks like it's aUIViewnot a webview. Also check that the outlet is connected to the right view. NBIBOutlets properties are conventionally declared asweaksince all ui elements are retained by their superviews. Note that changing the custom class of objects in IB doesn't always work correctly - look at the icon representing the webview in the view hierarchy. It should have a small compass icon contained in it. If it looks like a regular view, it is still a regular view, even if the custom class says something different.