0

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:

enter image description here

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?

kraftydevil
  • 5,144
  • 6
  • 43
  • 65
  • Have you resolved this issue? I have a very similar problem. My UIWebView is placed inside a UIScrollView which has enabled pagination, after user changes page, my WebView also being loaded and after 1 sec. it is gone. – Alexander Dec 22 '14 at 15:36
  • joining to the question - was this ever resolved? – Yoav R. Dec 20 '15 at 12:29
  • It was resolved, but unfortunately I can't recall the solution. I voted for @goodfella's answer but did not mark as resolved. This usually means I thought the answer was a good idea but it didn't solve the issue. Maybe try to follow my attempts as well as the one answer and it might lead you somewhere – kraftydevil Dec 20 '15 at 15:09

2 Answers2

1

Check if your WebView is not being removed from the view hierarchy somewhere by the application. I had similar problem and I've noticed that I unintentionally removed my WebView from the view hierarchy in some event handler.

Alexander
  • 780
  • 1
  • 8
  • 22
  • Can you give me some insight on how to do that or a link perhaps? – kraftydevil Dec 22 '14 at 20:07
  • Check where a link to yours WebView is being stored. Do you 100% sure that you have strong reference to it after application transitioned to Account screen. Maybe some of your code unintentionally removing WebView from view hierarchy. The insight is this: in your situation WebView removed when you completely changed screen (not in the time of the transition). So, I think the good idea if you are using UINavigationController, will be to look into the code located into navigationController:didShowViewController:animated: delegate method, if you have one. – Alexander Dec 23 '14 at 07:55
  • Another option will be to try Xcode Debug View Hierarchy tool, to see if your WebView is in place after it disappears. – Alexander Dec 23 '14 at 07:56
1

I faced a similar issue. But the problem with my setup was I was initializing the UI and the view in the Launchscreen.storyboard and not the Main.storyboard. Due to the nature of the Launchscreen.storyboard, it displays my view for some time before vanishing. Putting the view in the Main.storyboard fixed the issue.

learner
  • 3,168
  • 3
  • 18
  • 35