0

I wanna to scroll(down) on a UIWebView(iPad Application), where I will display a local pdf file, programmatically. I have added a UIWebView with the interface builder and linked it.

@interface ViewController : UIViewController <UIWebViewDelegate>

@property (weak, nonatomic) IBOutlet UIWebView *webView;

@end

This is my code for getting the pdf file and scrolling. The webViewDidFinishLoad function gets called.

@synthesize webView = _webView;

- (void)viewDidLoad
{
    [super viewDidLoad];

    NSString *path = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"pdf"];
    NSURL *targetURL = [NSURL fileURLWithPath:path];
    NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];

    self.webView.delegate = self;
    [self.webView loadRequest:request];
}

#pragma mark - UIWebViewDelegate

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    NSLog(@"didLoad");

    self.webView.scrollView.contentOffset = CGPointMake(0, 500);
}

I am using the iOS SDK 6.1, the iOS deployment target is also 6.1.

Heres the log:

2013-04-23 09:23:08.742 PDFViewer[3834:c07] DiskImageCache: Could not resolve the absolute path of the old directory.
2013-04-23 09:23:08.913 PDFViewer[3834:c07] didLoad

The UIWebView isn't scrolling. The pdf is still at the first page.

Niklas
  • 23,674
  • 33
  • 131
  • 170

2 Answers2

1

already answered here --- how to set scroll position on uiwebview , try calling content offset code snippet after a delay

Community
  • 1
  • 1
karthik
  • 1,271
  • 1
  • 14
  • 27
0

I don't think you need to set the webView.scrollView.contentOffset.

try this

[webView setScalesPageToFit:YES];
AMohan
  • 534
  • 1
  • 6
  • 15