0

私はここで迷っています。メソッドで UIImage オブジェクトを初期化しようとしています。ドキュメントのディレクトリなどを見て、キャッシュしないことを理解しています...

それぞれの URL またはパスを指定しますが、オブジェクトは常に nil です。この方法は決して成功しません。私のパスには常に先頭にファイルプレフィックスが含まれているためですか? このような?

ファイル:// .somedir/somedir/etc.../filename.jpg

この呼び出しで docs ディレクトリを取得してパスを作成します

//get the documents directory path
NSURL *docsPath = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];

// create the full image local path 
NSString *imageLocalPath = [NSString stringWithFormat:@"%@%u.jpg", docsPath, indexPath.row + 1];

次に、パス文字列を作成します。

4

1 に答える 1

1

これ

[NSString stringWithFormat:@"%@", docsPath];

本当にこれですか

[NSString stringWithFormat:@"%@", [docsPath description]];

これはあなたが望むものではありません。

このようなことを試してください:-

NSURL *docsURL = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
NSString *fileName = [NSString stringWithFormat:@"%u.jpg", indexPath.row+1];
NSString *filePath = [[docsURL path] stringByAppendingPathComponent:fileName];
于 2012-05-24T16:19:52.620 に答える