xcode で IMAGES というフォルダーを作成し、使用するすべての画像をそのフォルダーにコピーしました。
次のコードを使用してテーブルを更新し、画像を挿入しています。
NSString *picName = [NSString stringWithFormat:@"%@.jpg", [[theemplyees objectAtIndex:indexPath.row] valueForKey:@"EmpNo"]];
cell.empPicture.image = [UIImage imageNamed:picName];
場所を指定する必要がないことに注意してください。私がやりたいことは、ユーザーの画像が直接存在しない場合、画像をデフォルトの画像に設定することです。そのような:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
//Set image
NSString *imagePath = [documentsDirectory stringByAppendingPathComponent:picName];
//Check if the image exists at a given path
BOOL imageExists = [[NSFileManager defaultManager] fileExistsAtPath:imagePath];
//If the image doesn't exists download it.
if (!imageExists)
{
picName = @"nopicture.jpg";
}
問題は、上記を使用すると、常にファイルが存在しないと表示されることです。なし!Grrrファイルを間違った場所に置いていますか? Resources というディレクトリを作成してそこに配置しようとしましたが、まだ機能しませんでした。
どんな助けでも大歓迎です。あらゆる助けを前もって感謝します。
ジオ...