Имя файла NSString добавляет ненужные% 20 в пространство

РЕШЕНИЕ (спасибо Regexident)

У меня есть приложение, которое передает путь к файлу PDF в пользовательский - (id) init метод инициализации.Он добавляется в таблицу, и когда он выбирается, он вызывает оператор else для несуществующего файла:

- (void) gridView:(AQGridView *)gridView didSelectItemAtIndex:(NSUInteger)index {

NSLog (@"Selected theArgument=%d\n", index);

UIViewController *viewController = [[[UIViewController alloc]init]autorelease];
{
    //if file is built-in, read from the bundle
    if (index <= 3)
    {
        // first section is our build-in documents
        NSString *fileURLs = [_documentIconsURLs objectAtIndex:index];   
        NSLog(@"file url -%@", fileURLs);
        viewController = [[[xSheetMusicViewController alloc]initWithContentURL:fileURLs]autorelease];
    }
    //if file is external, read from URL
    else
    {
        // second section is the contents of the Documents folder
        NSString *fileURL = [_documentIconsURLs objectAtIndex:index];
        NSLog(@"file url -%@", fileURL);
        NSString *path;
        NSString *documentsDirectoryPath = [self applicationDocumentsDirectory];
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        path = [[paths objectAtIndex:0] stringByAppendingPathComponent:fileURL];


        if ([[NSFileManager defaultManager] fileExistsAtPath:documentsDirectoryPath])
        {
            viewController = [[[xSheetMusicViewController alloc]initWithDocumentURL:fileURL]autorelease];
        }
        else
        {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Failure!"                                                            message:@"The Selected File Does Not Exist"
                                                           delegate:nil
                                                  cancelButtonTitle:@"OK"
                                                  otherButtonTitles: nil];
            [alert show];
            [alert release];        
            return;
        }
    }
[self.navigationController setNavigationBarHidden:YES animated:NO]; 
[UIView beginAnimations:@"animation" context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.navigationController.view cache:YES]; 
[self.navigationController pushViewController:viewController animated:NO];
[UIView commitAnimations];  
    }
}

Поэтому всякий раз, когда у меня есть документ без пробела в его имени, он нажимает и запускает. Но когда в имени файла есть пробел, он говорит, что его не существует. И когда я удаляю метод if-else, он запускается, но вылетает из-за того, что файл не существует. Я попытался заменить% 20 ​​в пути к файлу обычным пробелом, но метод продолжает вызывать часть else.

Итак, путь к файлу не стандартизирован и не читается, или мой метод else неверен?

7
задан CodaFi 12 November 2011 в 20:40
поделиться