Question

I have a UISlider and I'm trying to pass its value into a window.scrollBy string. Basically, I'm attempting user-configurable auto-scrolling of web content.

The actual scrolling is working, but I'm unable to pass a value into the JavaScript by using the normal %f and , method.

[_webView stringByEvaluatingJavaScriptFromString:@"window.scrollBy(0,5);"];

I'm using the above, and I'd like the '5' to be substituted with the value of the slider.

Can this be done without the need for more Java (I'm absolutely not a JavaScript programmer!)

Était-ce utile?

La solution

First you have to build your javascript code using StringWithFormat:

NSString *string = [NSString stringWithFormat:@"window.scrollBy(0,%f);", slider.value];
[_webView stringByEvaluatingJavaScriptFromString:string];
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top