Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

knut

macrumors newbie
Original poster
Jun 30, 2009
21
0
Hi all
I have local html file wich is located in project folder
I want load local html
I add this code in applicationDidFinishLaunching
Code:
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"test" ofType:@"html"] isDirectory:NO]]];
but I get exception
Terminating app due to uncautgth exceptionn 'NSInvalidArgument',reason [NSURL initfileURLWithPath:isdirectory:]:nil string parametr
can you explain me why ? I get the directory dynamically why it is the nil?
Thanks
 
Try using loadData:MIMEType:textEncodingName:baseURL: or loadHTMLString:baseURL: instead.

thanks for reply
if I understand you correctly do

Code:
 NSString *filePath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"htm"];    
 NSData *htmlData = [NSData dataWithContentsOfFile:filePath];    
 if (htmlData) {    
 [webView loadData:htmlData MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:[NSURL URLWithString:@"http://iphoneincubator.com"]];    
 }
but what about baseURL:[NSURL URLWithString:mad:"????????"] my file is the local
? correct me please
thanks
 
one more question too
when i use such method for loading my local html
Code:
NSString *savedUrlString = [item objectForKey: @"itemUrl"];
NSString *tempUrlString = savedUrlString;
NSString *htmlFile = [[NSBundle mainBundle] pathForResource:tempUrlString ofType:@"html"];
NSData *htmlData = [NSData dataWithContentsOfFile:htmlFile];
NSString *imagePath = [[NSBundle mainBundle] resourcePath];
imagePath = [imagePath stringByReplacingOccurrencesOfString:@"/" withString:@"//"];
imagePath = [imagePath stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
[webView loadData:htmlData MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:[NSURL URLWithString:[NSString stringWithFormat:@"file:/%@//",imagePath]]];
on first line i got the error
error item undefind(first use in this funtion)
what means the first line and what type has the item ?
Thanks
 
Sounds like you are just copying and pasting code without understanding what it does. I suggest you step back from the real coding and go review the basics of Objective-C coding before you continue.
 
Sounds like you are just copying and pasting code without understanding what it does. I suggest you step back from the real coding and go review the basics of Objective-C coding before you continue.
Thanks it was copy past but before copy paste everything was understand for me except how get the path but now I solve this problem for me.
The question is close.
Thanks for reply
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.