Reputation: 19303
I've created a UIWebView from the IB and subclassed it to my needs. Somewhere inside my app I'm using the following code:
_mainWebView = nil;
_mainWebView = [[MyWebView alloc] initWithFrame:CGRectMake(0,0,320,460)];
_mainWebView.delegate = self;
NSURL *url = [NSURL URLWithString:@"http://www.google.com"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[_mainWebView loadRequest:request];
NSLog(@"WebView: %@", _mainWebView); //->> WebView: <MyWebView: 0x15403000; baseClass = UIWebView; frame = (0 0; 320 548); layer = <CALayer: 0x1544dac0>>
Which gives me a black screen with no content.
Upvotes: 3
Views: 3131
Reputation: 971
I faced the same issue,
What my issue was, the web view that I placed on the storyboard is crossing the borders of the view controller. When I pulled it back into the view controller it is working fine.
Upvotes: 0
Reputation: 1171
_mainWebView = [[MyWebView alloc] initWithFrame:CGRectMake(0,0,320,460)];
Above line of code tell that you create a new MyWebView, all hook up from IB will disconnect here. And you can show it by:
[self.view addSubview:_mainWebView];
If you draw and hook up from IB, simply comment out init a new one
Upvotes: 1
Reputation: 2552
It's most likely because you're setting _mainWebView to nil. This pretty much means you "unplug" the outlet you hooked up from Interface Builder. So the web view you're configuring in this code isn't connected to the screen at all. There are two options you can choose from:
1) Use Interface Builder, connect the outlets, and remove the first two lines of code in the snippet above.
2) Remove the web view from Interface Builder, remove the first line of code in the snippet above, and add [self.view addSubview:_mainWebView];
before you load the request.
By the way, I believe UIWebView is not to be subclassed, at least in an App Store release. It could be potentially breakable in future iOS's...
I hope this helps you!
Upvotes: 1