SOLVED (감사의 말)파일 이름 NSString은 공간에 불필요한 % 20을 추가합니다.
PDF의 파일 경로를 사용자 정의 -(id)init
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];
}
}
그래서 이름에 공백이없는 문서가있을 때마다 푸시되고 inits됩니다. 그러나 파일 이름에 공백이 있으면 파일이 존재하지 않는다고 말합니다. 그리고 if-else 메서드를 제거하면 init이 발생하지만 파일이 없기 때문에 충돌이 발생합니다. 파일 경로의 % 20을 일반 공백으로 바꾸려고 시도했지만이 메서드는 else 부분을 계속 호출합니다.
파일 경로가 표준화되고 읽을 수 없습니까, 아니면 다른 방법이 잘못 되었습니까?
코드에서 "% 20"과 변수 이름 ("... URL")을 판단하면 파일 URL ("% 20"등으로 공백을 "20"등으로 인코딩)을 혼란스럽게합니다 (공백, 기타). – Regexident
파일 url은 documentInteraction 예제에서 apple 메소드로 문자열로 변환됩니다. URL은 비 -DI 컨트롤러로 전달됩니다. 그래서 어떻게 고쳐야합니까? – CodaFi