1

here is my problem:

I need to find a way to load / attach text into a UIWebView while staying at the scroll position so that the new text appears seamless when hitting a button.

The scenario is that i display a page of a book and when the user scrolls to the end of the page i need to present an option to attach the next page into the webView.

I tried loading the new NSString containing of both Strings into the webView and then i scroll it to the last position but that creates a ugly " flicker " and it is hard to keep an eye on the page break.

My question is if anyone has experience or an idea on how to create i " seamless scrolling " effect by loading more text into a UIWebview and attach it to the existing text without reloading the whole UIWebview. Unfortunately i am very unexperienced with Javascript but i hope there is a script that dynamically adds text to the existing content.

Something like the scrollView in iBooks.

If a potential helper needs any specific information please let me know, otherwise if anyone can point out a way to direct my research to i would be very grateful.

TA

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • this might helps you [stackoverflow link](http://stackoverflow.com/questions/8886443/calling-javascript-using-uiwebview) [techniques scroll](http://engineering.linkedin.com/linkedin-ipad-5-techniques-smooth-infinite-scrolling-html5) – Yuyutsu Jan 07 '15 at 06:18

1 Answers1

1

Javascript is most likely your best bet, as you suspected. Luckily, adding text is easy. You can have a script like this (assuming you have a node identified as #myId in your HTML):

function addText(textToAdd) {
   var div = document.getElementById('myId');
   div.innerHTML = div.innerHTML + 'Extra stuff';
}

Then, you just need a way to call that function. If you want to call it from your Obj-C code, you'll want to do something like:

[self.webView stringByEvaluatingJavaScriptFromString:@"addText('text to add')"];

Of course, you could also use a framework like jQuery to further abstract the process of adding text to the existing HTML. Check out the following link for a few examples of adding text using Javascript: How to append data to div using javascript?

You may even want to or be able to do all the dynamic loading -- there are existing jQuery plugins for infinite scrolling already. (Google jQuery infinite scroll and peruse what's out there)

Community
  • 1
  • 1
jnpdx
  • 45,847
  • 6
  • 64
  • 94
  • hey, even its ages ago. Thank you for your answer. I didn't end up implementing it yet but i will do so soon. This seems very straightforward, thanks for your explanation – PowerStruggle Jun 06 '15 at 01:09