Open verhage opened 11 years ago
Can you post your viewForItemAtIndex: method? Might yield a clue as to the problem.
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]]; }
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...
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...
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 notifications@github.com 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.
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!
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,
My temp decision //CGSize size = [_delegate swipeViewItemSize:self]; CGSize size = self.bounds.size;
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?