I would like to make a set of help pages for an iOS app, and it seems logical to have a hypertext table of contents.
Is this possible, and if so, how do I wrap the page links in OBj-C?
Thanks..
I'm adding some code where I'm stuck. I'm using Apple's TransWeb example as a base..
- (void)viewDidLoad
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"page1" ofType:@"html"];
NSFileHandle *readHandle = [NSFileHandle fileHandleForReadingAtPath:path];
NSString *htmlString = [[NSString alloc] initWithData:
[readHandle readDataToEndOfFile] encoding:NSUTF8StringEncoding];
[self.webView loadHTMLString:htmlString baseURL:nil];
This is how I've set up the links in the html files..
<html>
<p>
Located in the Sierra Nevada foothills of <a href = "file://page2.html">California</a>
in the Sierra Nevada ...........
</p>
Thanks to Caleb for giving me the right answer..
I've changed my webView loadRequest as follows:
[super viewDidLoad];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"page1" ofType:@"html"]isDirectory:NO]]];
开发者_如何学运维
and changed the html file thus:
<a href = "page2.html">California</a>
Sure -- just use a UIWebView to display your HTML pages. Use relative URLs to link between pages.
Update: One problem I see in the code you posted is that your URL is incorrect. You've got a file url like this: file://page2.html
. That's incorrect -- if you want an url that's relative to the host's root, you can use: file:///page2.html
. That URL omits the host, which implies that the same host as the current page should be used. If you want to make the URL relative to both the host and the directory of the current page, leave off the whole scheme: page2.html
. So your anchor tag could look like:
<a href = "page2.html">California</a>
Another thing to consider is that you probably don't need to bother with the NSFileHandle. Just load the root page's data directly into a string:
NSString *htmlString = [NSString stringWithContentsOfFile:path encoding: NSUTF8StringEncoding error:nil];
精彩评论