4

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.

1
  • 2
    Check the custom class of webView in your xib/storyboard - it looks like it's a UIView not a webview. Also check that the outlet is connected to the right view. NB IBOutlets properties are conventionally declared as weak since 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. Commented Mar 29, 2015 at 20:26

1 Answer 1

8

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

Sign up to request clarification or add additional context in comments.

1 Comment

The element was defined in the.h file as a UIWebView element. However, I removed it and added it again to the .h file from IB and this time it works as expected. Looks like something was screwed up in the configuration of the app.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.