[英]Unable to load “path” with “stringWithFormat” objective-c
i have this method that load html file from my application into UIWebView. 我有这种方法可以将HTML文件从我的应用程序加载到UIWebView中。 the issue is that this file name change from time to time - and i cant get it to work.
问题是此文件名不时更改-我无法使其正常工作。 this is my code:
这是我的代码:
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]];
and i get this problem: [NSURL initFileURLWithPath:]: nil string parameter.
我得到这个问题:
[NSURL initFileURLWithPath:]: nil string parameter.
when i use it for example in this way its work: 例如,当我以这种方式使用它的工作时:
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]];
what should i do to fix it ? 我该怎么解决? Thanks !
谢谢 !
////////// update //////////更新
this is the whole method: hope you can help me. 这就是整个方法:希望您能帮助我。
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]];
Ok, the problem was that i want in focus and forgot to add the html files into my project. 好的,问题是我想集中精力,却忘记将html文件添加到我的项目中。 So to all of you who will need this code sometime in the future - its working perfect.
因此,对于将来在某个时候需要此代码的所有人来说,它的工作原理是完美的。
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSUserDefaults *默认值= [NSUserDefaults standardUserDefaults]; NSString *zodiacProfile = [defaults valueForKey:@"zodiacProfile"];
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]];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.