EDIT:
The UIWebView is first initialized in FirstViewController
like this:
- (void)viewDidLoad {
[super viewDidLoad];
self.webView = [[UIWebView alloc] initWithFrame:self.view.frame];
self.webView.delegate = self;
[self.view addSubview: self.webView];
NSURL *url = [NSURL URLWithString:BASE_URL];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:urlRequest];
}
The reference to this UIWebView
is passed on to the SecondViewController
, and I add it as a subview like this:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.webView.delegate = self;
[self.view addSubview:self.webView];
}
This attaches a UIWebView into a View Controller's view. If I call this function inside viewDidAppear
, I get a UIWebView that fits the whole screen. However, if I call it inside viewWillAppear
, UIWebView only takes half the whole screen's size. I tried comparing viewController.view
's sizes for viewWillAppear
and viewDidAppear
but they seemed to be the same.
According to this very similar post it's appropriate to resize subviews in viewDidLayoutSubviews
. So I tried the following:
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
self.webView.frame = self.view.bounds;
}
but it still looks like this: