iphonexcode4uiwebviewios5

Navigating a Pdf using UIWebview not working in IOS 5


I have recently upgraded to Xcode 4 and I've found that an app which has worked perfectly well for over a year is now not working under Ios 5. The app navigates a Pdf in UIWebview and uses the following code to move to any page within the Pdf.

[self.pdfNavigateController.webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"window.scrollTo(0, %d);", self.pdfNavigateController.scrollPosition]];

When I use any simulator from 4.2 down the code works perfectly but under the Ios 5 simulator the code wont work.

Looking through the forum there seems to be a number of issues where classes have changed. What has changed under Ios 5 and what can I do to rectify the problem?


Solution

  • You can use UIWebView's Scrollview for navigation as Javascript is no more supported: Below is my code worked fine for me.

        [aWebView.scrollView setContentOffset:CGPointMake(x, y)];
    

    The contentOffset accepts a CGPoint as argument. Here x and y are integer values representing the scrollPosition. If you want to get current x and y co-ordinates for webView, below is the code which you can use:

    NSInteger x = aWebview.scrollView.contentOffSet.x;
    NSInteger y = aWebview.scrollView.contentOffset.y;
    

    Note: ScrollView is introduced in IOS 5 and will not work on earlier IOS versions. Javascript function are available for earlier versions. So you can check for device version and implement code accordingly.