views:

71

answers:

1

In my app I have a UIWebView which loads different rtf files. I use this function to load these files:

- (void)loadFile:(NSString*)file
{
NSString* resourcePath = [[NSBundle mainBundle] resourcePath];
NSString* sourceFilePath = [resourcePath stringByAppendingPathComponent:file];
NSURL* url = [NSURL fileURLWithPath:sourceFilePath isDirectory:NO];
NSURLRequest* request = [NSURLRequest requestWithURL:url];
[webview loadRequest:request];
}

The UIWebView displays nothing. When I enter the debugger, the file string value is which I need, but resourcePath and sourceFilePath values are "nil". What am I doing wrong?

Thanks in advance!

+1  A: 

Try using -pathForResource:ofType: instead.

NSString* sourceFilePath = [[NSBundle mainBundle] pathForResource:file ofType:nil];
KennyTM
sourceFilePath value is "nil", anyway
Knodel
@Knodel: ? This will return `nil` only if that `file` does not exist. Make sure the `file` exists.
KennyTM
file is definitely in my project. Maybe the problem is that I use NSString *Path = [[NSBundle mainBundle] bundlePath]; NSString *DataPath = [Path stringByAppendingPathComponent:@"Data.plist"]; - in my appdelegate.m?
Knodel
@Knodel: I don't think so. Also, you should really use `[[NSBundle mainBundle] pathForResource:@"Data" ofType:@"plist"]`
KennyTM
Thanks! I've solved the problem - I had an rtfd file, but UIWebView loads only rtfd.zip, that's why it didn't show anything. Thank you! (anyway, I can't understand, why sourceFilePath was nil :) )
Knodel