Невозможно загрузить «путь» с «stringWithFormat» target-c - PullRequest
0 голосов
/ 22 марта 2012

У меня есть этот метод, который загружает 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]];

что мне сделать, чтобы это исправить? Спасибо!

////////// update

это весь метод: надеюсь, ты сможешь мне помочь.

   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]];

1 Ответ

0 голосов
/ 23 марта 2012

Хорошо, проблема была в том, что я хочу сфокусироваться и забыл добавить html-файлы в свой проект. Так что для всех вас, кому понадобится этот код когда-нибудь в будущем - он отлично работает.

NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults]; NSString * zodiacProfile = [значение по умолчаниюForForKey: @ "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]];
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...