views:

259

answers:

1

It turns out that if you load data into a UIWebView using loadHTMLString, that the webView will always return NO for canGoBack and canGoForward properties. Unfortunately, I have to extract fragments of text from a large file and then put that text into a webView with loadHTMLString.

[aWebView loadHTMLString:aString baseURL:nil];

In order for the canGoBack and canGoForward properties to reflect the proper values, one must use

[aWebView loadRequest:(NSURLRequest *)request]

How can I convert a string of text into a request that can be processed with loadRequest?

A: 

You could override NSURLRequest to return your string in the HTTP body. The NSURLRequest class includes 2 messages:

-(NSData*)HTTPBody 

and 

-(NSInputStream*)HTTPBodyStream

Overriding these messages to return your NSString as either NSData or NSInputStream might work.

Converting an NSString to NSData is easy

[aStr dataUsingEncoding: NSASCIIStringEncoding];

Once you have this you can convert NSData into an NSInputStream

[NSInputStream inputStreamWithData:someData];
Randaltor