Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

first webview stays empty #57

Open
verhage opened this issue Jul 23, 2013 · 8 comments
Open

first webview stays empty #57

verhage opened this issue Jul 23, 2013 · 8 comments

Comments

@verhage
Copy link

verhage commented Jul 23, 2013

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?

@nicklockwood
Copy link
Owner

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

@verhage
Copy link
Author

verhage commented Jul 24, 2013

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
Copy link
Author

verhage commented Aug 12, 2013

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
Copy link
Author

verhage commented Aug 12, 2013

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...

@nicklockwood
Copy link
Owner

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.

@verhage
Copy link
Author

verhage commented Aug 13, 2013

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!

@couchoud
Copy link

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,

@grom24h
Copy link

grom24h commented Sep 17, 2014

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants