「サムネイル」、「ファイル名」、「日付変更」の 3 つの列を持つ NSTableview があります。ファイル名列と更新日列には、S3ListObjectResponse の出力が入力されます。「サムネイル」列の画像は、マシンのローカル ディレクトリから読み込まれます。ファイルが見つからない場合は、S3 クラウドからダウンロードします。問題は、ファイルが見つからず、サムネイル用の空のセルが残っている場合に、データを NSArrayController に挿入する方法です。これが今の私の仕事です:
- (IBAction)checkCloud:(id)sender {
AmazonS3Client *s3 = [AmazonClientManager s3];
S3ListObjectsRequest* listObjectsRequest = [[S3ListObjectsRequest alloc] initWithName:@"hello-testing"];
NSRange range = NSMakeRange(0, [[_fileListAC arrangedObjects] count]);
[_fileListAC removeObjectsAtArrangedObjectIndexes:[NSIndexSet indexSetWithIndexesInRange:range]];
@try {
    S3ListObjectsResponse* response = [s3 listObjects:listObjectsRequest];
    NSMutableArray* objectSummaries = response.listObjectsResult.objectSummaries;
    //looping through the objSummary and add into the NSArrayController
    for ( S3ObjectSummary* objSummary in objectSummaries ) {
        NSImage *thumbnail = [[NSImage alloc] init ];
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"];
        NSDate *s3date = [dateFormatter dateFromString:[objSummary lastModified]];
        NSArray *fileName =  [[objSummary key] componentsSeparatedByString:@"/"];
        if([[fileName objectAtIndex:0] localizedCaseInsensitiveCompare:@"Range"] == NSOrderedSame) {
            NSLog(@"file name %@ ",[fileName objectAtIndex:1]);
           // Check for files in side the bucket's folders 
           if([[fileName objectAtIndex:1] length]){
                NSString *thumbnailFile = [[fileName objectAtIndex:1] stringByAppendingString:@"_thumb.png"];
                BOOL isDir;
                NSFileManager *fileManager = [NSFileManager defaultManager];
                NSString *filePathPart1 = [@"/Users/" stringByAppendingString:[[NSHost currentHost] localizedName]];
                NSString *filePath = [[[[ filePathPart1 stringByAppendingString:@"/Documents/Test/" ] stringByAppendingString:@"Range" ] stringByAppendingString:@"/Thumbnail/"] stringByAppendingString:thumbnailFile];
               // If file exists then add into the thumbnail column
               if([fileManager fileExistsAtPath:filePath isDirectory:&isDir]){
                    thumbnail = [[NSImage alloc] initWithContentsOfFile:filePath];
                }else{
                     NSLog(@"file %@ not found",thumbnailFile);
                    //Downloading from the S3 Cloud Asynchronously
                    doneDownload = NO;
                    AmazonS3Client *s3 = [AmazonClientManager s3];
                    S3GetObjectRequest *gor = nil;
                    @try {
                        gor = [[S3GetObjectRequest alloc] initWithKey:[[@"Range/Thumbnail/"  stringByAppendingString:[fileName objectAtIndex:1]] stringByAppendingString: @"_thumb"] withBucket:@"thumbnail-pic" ];
                        gor.delegate = self;
                        [s3 getObject:gor];
                    }
                    @catch (AmazonClientException *exception) {
                        doneDownload = YES;
                    }
                    do {
                        [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
                    } while (!doneDownload);
                    gor.delegate = nil;
                }
            }else{
                //If its the actual bucket folder and not file then load a default image 
                thumbnail = [NSImage imageNamed:@"Range.png"];
            }
        }
           [_fileListAC addObject:[NSMutableDictionary  dictionaryWithObjectsAndKeys:thumbnail,@"thumbnail", [objSummary key],@"Files",s3Date,@"Date Modified", nil]];
    }
}
@catch (NSException *exception) {
    NSLog(@"Cannot list S3 %@",exception);
}
//Display the table on loading the NSArrayController
[_cloudFileList makeKeyAndOrderFront:nil]; 
}
デリゲートメソッドを確認しました
 -(void)request:(AmazonServiceRequest *)request didCompleteWithResponse:(AmazonServiceResponse *)response{
NSData *imageData = [response body];
_coreDataImageView.image = [[NSImage alloc] initWithData:imageData];
doneDownload = YES;
}
coredataimageview はテスト イメージ ウェルです。イメージはダウンロードされましたが、アレイ コントローラに追加し直したいと考えています。問題は、ローカル ディレクトリに 3 つのファイルがなく、そのファイル名と日付変更値をアレイ コントローラに挿入できない場合です。これについて何か助けはありますか?