SOLVED(ありがとうRegexident)ファイル名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];
}
}
したがって、名前にスペースがない文書がある場合は、しかし、ファイル名に空白がある場合、ファイル名は存在しないと言います。そして、if-elseメソッドを削除すると、initが発生しますが、ファイルが存在しないためにクラッシュします。私はファイルパスの%20を通常のスペースに置き換えようとしましたが、メソッドはelseパーツを呼び出し続けます。
ファイルのパスは標準化されていないのですか?
"%20"と変数ネーミング( "... URL")がコード内にあると判断すると、ファイルパス(スペースを "%20"等)。 – Regexident
ファイルurlは、documentInteractionの例からappleメソッドの文字列に変換されます。しかし、URLは非DIコントローラに渡されます。それで、私はそれをどうやって修正するのですか? – CodaFi