NSArray
画像付きです。画像名はA、B、C、Dです。NSLog
配列からこれらの画像の名前を付ける必要があります
NSLog(@"Name == %@", [Array objectAtIndex:1]);
これの代わりに何を使用する必要がありますか?
NSArray
画像付きです。画像名はA、B、C、Dです。NSLog
配列からこれらの画像の名前を付ける必要があります
NSLog(@"Name == %@", [Array objectAtIndex:1]);
これの代わりに何を使用する必要がありますか?
AUIImage
はそのファイル名を保存しません。それらが作成されたファイルの名前を追跡したい場合は、それらも保存する必要があります。
ワトソンが示唆しているように、それは不可能です。このためには、imageNameを保存できる別の配列を取得する必要があります。それ以外の場合は、imageNameをキーとしてNSMutableDictionary
保存し、 Arrayオブジェクトをそのオブジェクトとして保存して後で読み取ることができます。
私の知る限り、UIImage
オブジェクトから画像ファイルの名前を取得することはできません。これを実行したい場合は、名前を画像と一緒にNSDictionary
オブジェクトに保存できます。
NSArray * imageNames = [NSArray arrayWithObjects:@"A.png", @"B.png", @"C.png", nil];
NSMutableArray * array = [NSMutableArray arrayWithCapacity:[imageNames count]];
for (NSString * imageName in imageNames)
[array addObject:[NSDictionary dictionaryWithObjectsAndKeys:
[UIImage imageNamed:imageName], @"image", imageName, @"name", nil]];
次に、次のようにログに記録できます。
NSLog(@"name = %@", [[array objectAtIndex:1] valueForKey:@"name"]);
配列の「description」メソッドを連結された画像の名前でオーバーライドすると、正常に機能する可能性があります。
この場合、NSLogは、各オブジェクトにそれ自体を説明する文字列を要求し、オブジェクトに-descriptionメソッドを送信することで機能します。(注:オブジェクトがdescriptionメソッドをオーバーライドしない場合、NSObjectから継承された-description実装を取得します。これは、次のようになる傾向があります。UsingTheDescriptionMethodを参照してください。
注:descriptionメソッドは、デバッグ目的でのみ使用する必要があります
よろしく。
それはいけません。A、B、C、Dがインスタンス変数である場合、それらはあなたが制御できる唯一のものです。
if ((UIImage*)[Array Objectatindex:1] == A)
bla-bla-bla you know that it's "A"
割り当てられると、画像名に到達できません。
NSLog
全体NSArray
を使用したい場合は、これを使用してください。
NSArray *_array = // your array
NSLog(@"array == %@", _array);
更新:#1
使用可能な方法の1つは次のとおりです。オブジェクトのみで埋めるのNSMutableArray
ではなく、次のような内容でUIImage
「NSDictionary」オブジェクトをに追加する必要があります。NSMutableArray
NSMutableArray *_array = [NSMutableArray array];
// you could put this part inside a loop if you like
NSString *_imagePathWithName = @"...";
UIImage *_newImage = [UIImage imageNamed:_imagePathWithName]; // when you load it from you application bundle
// or [UIImage imageWithContentsOfFile:_imagePathWithName]; // loading from other place
NSDictionary *_imageDictionary = [NSDictionary dictionaryWithObjectsAndKeys:_newImage, @"keyForUIImage", _imagePathWithName, @"keyForFullPathAndName", nil];
[_array addObject:_imageDictionary];
配列から名前を読み取りたい場合
for (NSDisctionary *_dictionary in _array) {
UIImage *_image = (UIImage *)[_dictionary valueForKey:@"keyForUIImage"];
NSString *_fullPathWithName = (NSString *)[_dictionary valueForKey:@"keyForFullPathAndName"];
// do whatever you'd like with the images and the path
}