RahulMishra RahulMishra - 2 months ago 9
Objective-C Question

App is crashing while loading request in UIWebVIew - ObjectiveC

I am loading an URL to my

webView
but just after starting
loadRequest
my App is crashing.

My
WebView
is inside a custom
UIView
Class with
XIB
and I am adding my view like this:

WebViewContainer *webViewContainer = [[[NSBundle mainBundle] loadNibNamed:@"WebViewContainer" owner:nil options:nil] firstObject];
[webViewContainer startLoadingURL:kPersonalWebsiteURL];
webViewContainer.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);

[self.view addSubview:webViewContainer];


My
startLoadingURL
method:

- (void)startLoadingURL:(NSString *)url
{
NSURL *urlToLoad = [NSURL URLWithString:url];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:urlToLoad];
[self.webView loadRequest:requestObj];
}


Here is the Interface Builder Configuration:

enter image description here

Here is the Error Message i am only getting this error message not getting any logs.

enter image description here

Answer

Try to retype nil to self as the owner parameter. So you may have to replace:

WebViewContainer *webViewContainer = [[[NSBundle mainBundle] loadNibNamed:@"WebViewContainer" owner:nil options:nil]

with

WebViewContainer *webViewContainer = [[[NSBundle mainBundle] loadNibNamed:@"WebViewContainer" owner:self options:nil]
Comments