I'm trying to figure out how to troubleshoot and/or solve an issue where a UIWebView clearly loads but then disappears.
After tracing in the debugger, the webView is disappearing after viewDidAppear:
The content flashes briefly on screen and is then gone:
To help me trace, I've got some KVO set up to monitor the contentSize:
- (void)viewDidLoad
{
[super viewDidLoad];
[self startObservingChangesInView:self.webView];
}
- (void)dealloc {
[self stopObservingChangesInView:self.webView];
}
- (void)startObservingChangesInView:(UIView *)view {
[view addObserver:self forKeyPath:@"contentSize" options:0 context:&kObservingChangesContext];
}
- (void)stopObservingChangesInView:(UIView *)view {
[view removeObserver:self forKeyPath:@"contentSize" context:&kObservingChangesContext];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if (context == &kObservingChangesContext) {
UIView *view = object;
NSLog(@"View changed for keypath, '%@': '%@'", keyPath, view.description);
} else {
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
}
Extra context
There's more going on in my UIWebView than shown above, I just wanted to show my current mechanism for monitoring keys.
There are some cases where the load works and stays.
Works
Run app in simulator
Log in
Open Menu
Open Url
Doesn't work
It stops working when following these steps:
Run app in simulator
Log in
Open Menu
Open Url
Logout
Login
Open Menu
Open Url
The problem is that I'm not holding on to any references after logging the user out of the app. The webView is created a new object every time it is pushed with UINavigationController
.
So how can I go about solving this? Either there is a known solution or maybe there are there variables I should be tracing with KVO?