开发者

Navigate to prev and next pdf file?

I got a pdf viewer in a uiwebview, from Daniel Barry http://github.com/danberry/PDF-Viewer and it works really well, it displays a pdf doc that you can scroll up and down.

Now I would like to display just one page at the time and also have a menu underneat the pdf page with a prev and next button. Can anybody help a newbe to figure out how? Thanks!

#import "PDFViewController.h"   // PDF View Controller

@implementation PDFViewController

// Synthesiz开发者_如何转开发e UI Element properties
@synthesize webView;
// Synthesize Variable properties
@synthesize pdfURL;

#pragma mark -
#pragma mark UIViewController methods
- (void)viewDidLoad {
    [super viewDidLoad];

    pdfURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"stuff pdf" ofType:@"pdf"]];
    [webView loadRequest:[NSURLRequest requestWithURL:pdfURL]];
    webView.transform = CGAffineTransformScale( webView.transform, 1.00, 1.00 );
}

#pragma mark -
#pragma mark Memory Management
- (void)dealloc {
    [webView release];

    [pdfURL release];

    [super dealloc];
}

@end


I think a webview should show PDFs by using a default request, no need to have a new implementation?

Anyways... There are 2 methods you could check out and link to your prev and next button

- (void)goBack:(id)sender 
{
 if ([webView canGoBack]) {
  [webView goBack];
 }
}

- (void)goForward:(id)sender
{
 if ([webView canGoForward]) {
  [webView goForward];
 }
}

Here is the documentation of UIWebView where the methods are explained in detail: http://developer.apple.com/iphone/library/documentation/uikit/reference/UIWebView_Class/Reference/Reference.html

EDIT: Oh I think, I first misunderstood your question...

Just create an Array of the PDF URLs that you want to load. Create a counter variable that will hold the index value of the currently opened PDF.

And finally similar to the methods above create a forward and backward method and link them to the prev and next buttons. In those methods you increment or decrement the counter by 1 and load the appropriate index from the array [array objectAtIndex:counter] so the next or previous PDF is opened.

If you need more help, let me know...


ok im gonna post this as another answer...

In the header file add

NSArray *arrURLs;
NSInteger *currentIndex;

and make the array a property (retain), synthesize it in the .m file, also release it in dealloc.

In - (void)viewDidLoad initalize the array with all the URLs and set the currentIndex to 0.

arrUrls = [[NSArray alloc] initWithObjects:@"url", @"url", ..., nil];
currentIndex = 0;

add two methods that you call something like prevPage and nextPage and link them to your buttons. In those methods you do something like...

// next page
currentIndex += 1;
NSString *str = [arrUrls objectAtIndex:currentIndex];
NSURL *url = [NSURL URLWithString:str];
[webView loadRequest:[NSURLRequest requestWithURL:url]];

I would probably create another method where you set the currentIndex and check if it is in the correct bounds (e.g. should not be smaller than 0 and must be smaller than the length of the array). Than you can change the first line and let the method call handle the in/decrementing of the variable.

hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜