iPhone: Wrapping text around image
From what I have gathered, wrapping text around an image is possible using a UIWebView displaying a local html file. (I have a local html file called index.html)
The following code inserted in the viewDidLoad method seems to crash the application with error. *** Terminating app due to uncaught exception 'NSInvalidArgument开发者_JAVA技巧Exception'
This example may look familiar. It seems to be the recurring example which comes up in Google searches. If anyone knows of another way, example, or reason for why it is crashing, please let me know.
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"] isDirectory:NO]]];
Please note, "webView" is an IBOutlet of a UIWebView, and I was able to load an html string into it; just not a file. Also, the name of the html file is exactly "index.html" as stated in pathForResource and ofType.
This is what I do, which has more error handling and stuff:
NSError *error = nil;
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"index"
ofType:@"html"];
html = [NSString stringWithContentsOfFile:filePath
encoding:NSUTF8StringEncoding error:&error];
if (error != nil)
NSLog (@"Error loading index.html: %@", [error localizedDescription]);
NSString *basePath = [[NSBundle mainBundle] resourcePath];
NSURL *baseURL = [NSURL fileURLWithPath:basePath];
[webView loadHTMLString:html baseURL:baseURL];
精彩评论