私のアプリケーションからUIWebViewにhtmlファイルをロードするこのメソッドがあります。 問題は、このファイル名が時々変更されることです。このファイル名は動作しません。 これは私のコードです:"stringWithFormat" objective-cで "path"を読み込めません
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]];
「MyFileNameString」の内容は何ですか?これが就労と就労の唯一の違いであれば、それは問題です。 – trojanfoe
最初の例では、 'MyFileNameString'があなたが思っている値に設定されていることを確かめていますか?その名前のファイルがバンドルに存在していることを確認してください。 – jonkroll
アプリをビルドする前に、すべてのhtmファイルが正しいターゲットに追加されていることを確認してください(ファイルのコピービルドフェーズ)? – Alladinian