Using UITableView to show on-board pdfs
I'm trying to set up a table view for the user to choose from a series of on-board pdfs to be displayed in a UIWebView
. I have this for displaying the pdfs:
NSString *urlAddress = [[NSBundle mainBundle] pathForResource:@"1" ofType:@"pdf"];
NSURL *url = [NSURL fileURLWithPath:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[biblioView loadRequest:requestObj];
Which works fine. What I 开发者_如何学运维can't work out is how to use the result of didSelectRowAtIndexPath
in the table to load the selected pdf called 1 thru x into the UIWebView
.
Suspect it's setting up a variable, loading the result into it and then somehow deploying that in the pdf code above, but I just can't get it.
I'm sure the obvious answer to this question is "learn some basic coding, doofus", but I'm doing this as a favour, in a hurry and from a standing start, so any hints/tips/snippets would be VERY gratefully received. Thank you...
You need a UITableViewController
to display the PDF list, checkout some Apple example e.g. http://developer.apple.com/library/ios/#samplecode/TableViewSuite/Introduction/Intro.html%23//apple_ref/doc/uid/DTS40007318 to get started, what you need to understand is to implement UITableViewDataSource
and UITableViewDelegate
.
Then you need a UIViewController
which contains an UIWebView
, load PDF as your code. You can setup a property to get the different PDF source from the UITableViewDelegate
's -tableView:didSelectRowAtIndexPath:
.
To add to the above answer..
Your UITableView
will be back by some data structure, possibly static in your case. You override the the UITableViewDatasource
method cellForRowAtIndexPath....
to to tell the table view what to display in each cell (it's called once for each cell in sequence). You would usually be using the indexPath.Row
parameter to query your data structure (eg an array index).
When a user selects a table view cell, your overridden UITableViewController
implementation (subclass) method
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath
will be called. You can use the index selected to re-query the data structure to determine which pdf the user selected.
It's then just a case of dynamically building your url address.
精彩评论