我有这个方法将html文件从我的应用程序加载到UIWebView中。 问题是这个文件名不时改变 - 我无法让它工作。 这是我的代码:
NSString *path;
NSBundle *thisBundle = [NSBundle mainBundle];
path = [thisBundle pathForResource:[NSString stringWithFormat:@"%@_file",MyFileNameString] ofType:@"htm"];
// make a file: URL out of the path
NSURL *instructionsURL = [NSURL fileURLWithPath:path];
[ProfileHtml loadRequest:[NSURLRequest requestWithURL:instructionsURL]];
我遇到了这个问题:[NSURL initFileURLWithPath:]: nil string parameter.
当我以这种方式使用它的工作时:
NSString *path;
NSBundle *thisBundle = [NSBundle mainBundle];
path = [thisBundle pathForResource:[NSString stringWithFormat:@"%@_file",@"amir"] ofType:@"htm"];
// make a file: URL out of the path
NSURL *instructionsURL = [NSURL fileURLWithPath:path];
[ProfileHtml loadRequest:[NSURLRequest requestWithURL:instructionsURL]];
我应该怎么做才能解决这个问题? 谢谢!
//////////更新
这是整个方法: 希望你能帮助我。
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *zodiacProfile = [defaults valueForKey:@"zodiacProfile"];
NSLog(@"zodiacProfile: %@",zodiacProfile);
[zodiacWallpaper setImage:[UIImage imageNamed:[NSString stringWithFormat:@"Wallpaper_%@",zodiacProfile]]];
zodiacTitle.text = [NSString stringWithFormat:@"About %@",zodiacProfile];
NSString *path;
NSBundle *thisBundle = [NSBundle mainBundle];
path = [thisBundle pathForResource:[NSString stringWithFormat:@"%@HTM",zodiacProfile] ofType:@"htm"];
NSURL *instructionsURL = [NSURL fileURLWithPath:path];
NSLog(@"zodiac: %@",zodiacProfile);
NSLog(@"path: %@",path);
NSLog(@"url: %@",instructionsURL);
[ProfileHtml loadRequest:[NSURLRequest requestWithURL:instructionsURL]];
答案 0 :(得分:0)
好的,问题是我想要关注并忘记将html文件添加到我的项目中。 所以在将来的某个时候需要这些代码的所有人 - 它的工作完美。
NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults]; NSString * zodiacProfile = [默认值valueForKey:@“zodiacProfile”];
NSLog(@"zodiacProfile: %@",zodiacProfile);
[zodiacWallpaper setImage:[UIImage imageNamed:[NSString stringWithFormat:@"Wallpaper_%@",zodiacProfile]]];
zodiacTitle.text = [NSString stringWithFormat:@"About %@",zodiacProfile];
NSString *path;
NSBundle *thisBundle = [NSBundle mainBundle];
path = [thisBundle pathForResource:[NSString stringWithFormat:@"%@HTM",zodiacProfile] ofType:@"htm"];
NSURL *instructionsURL = [NSURL fileURLWithPath:path];
NSLog(@"zodiac: %@",zodiacProfile);
NSLog(@"path: %@",path);
NSLog(@"url: %@",instructionsURL);
[ProfileHtml loadRequest:[NSURLRequest requestWithURL:instructionsURL]];