SwipeView icon indicating copy to clipboard operation
SwipeView copied to clipboard

first webview stays empty

Open verhage opened this issue 11 years ago • 8 comments

I try to display a series of full screen UIWebViews. All data displayed in the views is locally available. Sometimes, the first UIWebView remains white on display. Swiping to the next UIWebView and back, reveals the contents of the first view.

It seems to be timing related. Do you have any idea what could be the problem?

verhage avatar Jul 23 '13 20:07 verhage

Can you post your viewForItemAtIndex: method? Might yield a clue as to the problem.

nicklockwood avatar Jul 23 '13 21:07 nicklockwood

Of course:

  • (UIView *)swipeView:(SwipeView *)swipeView viewForItemAtIndex:(NSInteger)index reusingView:(UIView *)view { NewsItem *newsItem = [_newsItems objectAtIndex:index]; ShowNewsItemView *showNewsItemView = (ShowNewsItemView *) view; if (showNewsItemView == nil) { showNewsItemView = [[ShowNewsItemView alloc] initWithFrame:self.view.bounds]; }

    showNewsItemView.newsItem = newsItem; [showNewsItemView renderNewsItem];

    return showNewsItemView; }

ShowNewsItem view is a view with a UIWebView as a subview along with a banner view for advertisements (which always renders correctly on first appearance).

The renderNewsItem function constructs the HTML and loads it into the webView:

  • (void)renderNewsItem { ... code to construct NSString *html ....

    NSURL *baseURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]; [self.webView loadHTMLString:html baseURL:baseURL]; [self.webView setBackgroundColor:[UIColor clearColor]]; }

verhage avatar Jul 24 '13 08:07 verhage

Hi Nick,

I created a small test project to reproduce the issue. You can find it here: https://github.com/verhage/swipeview_issue

Just run it in the simulator (iOS 5.0+) and you'll see that on startup the screen remains empty. Slide to the right and the second item slides into view. Now slide back to the left and the first item appears.

I'm going to play around with this a little, still no clue what happens though...

verhage avatar Aug 12 '13 19:08 verhage

Hmmm, I just got a step closer to resolving the issue. Seems it has something to do with the CSS. Right now, the CSS is in its own file and included through a link tag. I removed the link and included the CSS in the HTML between style tags and it seems to work!

There is still an issue with images though. Images won't load the first time a view is shown...

verhage avatar Aug 12 '13 19:08 verhage

I've seen something similar before with web views. I think it's some kind of race condition caused by the webview being offscreen when the HTML is first loaded.

FWIW, adding this seems to fix it as well (although it flickers). Maybe it will help you get closer to a solution though. If you find a fix let me know and I'll see if there's some way to add it to the library itself.

  • (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated];

    //delay until next runloop cycle dispatch_async(dispatch_get_main_queue(), ^{ [self.swipeView reloadItemAtIndex:0]; }); }

Nick

On 12 Aug 2013, at 20:57, verhage [email protected] wrote:

Hmmm, I just got a step closer to resolving the issue. Seems it has something to do with the CSS. Right now, the CSS is in its own file and included through a tag. I removed the link and included the CSS in the HTML between tags and it seems to work!

There is still an issue with images though. Images won't load the first time a view is shown...

— Reply to this email directly or view it on GitHub.

nicklockwood avatar Aug 12 '13 20:08 nicklockwood

Thanks, didn't think of that one :)

Got a 'solution' to the flickering. Flickering only occurs when the first load has succeeded, when the content is replaced with itself. My workaround is to take a screen grab of part of the web view and only reload when the screen grab is all white.

A complete hack of course, but does the trick for me!

verhage avatar Aug 13 '13 15:08 verhage

Just thought I would mention...

I had a similar problem when loading PDFs through a UIWebView instance, but in my case the file just wouldn't load. I noticed that SwipeView would add/remove the initial view multiple times if the dateSource link had been setup in a xib or storyboard to a parent view controller. I manually set that connection in the 'viewWIllAppear' method of the parent view controller and everything worked fine.

It might of be a red herring masking something more dysfunctional in my code, but I do know that multiple url request can cause issues when multiple UIWebView instances are initialized and one is in the middle of its request.

Thanks,

couchoud avatar Mar 28 '14 15:03 couchoud

My temp decision //CGSize size = [_delegate swipeViewItemSize:self]; CGSize size = self.bounds.size;

grom24h avatar Sep 17 '14 20:09 grom24h