Pregunta

Quiero agregar ICDCodeDictionary a la lista de retroceso, pero cambia todos los elementos de la lista de retroceso. Después de este proceso, son los mismos con el último elemento agregado. ¿Cómo puedo resolver esto? Seguí este enlace.http://iphonedevsdk.com/forum/iphone-sdk-develovelment/88286-adding-object-to-nsmutablearray-changes-all-objects.htmlPero nada pasó. Gracias.

NSMutableDictionary *icdcodeDictionary;
@property (nonatomic, retain) NSMutableArray *backlist;
[self.backlist addObject:icdcodeDictionary];

Consecuencia de

NSLOG (@"Backlist %D Índice: %@", self.backlist.count-2, [ICDCodeDictionary ObjectForKey:@"Name"]);

NSLOG (@"Backlist %D Índice: %@", self.backlist.count-1, [ICDCodeDictionary ObjectForKey:@"Nombre"]):

backlist 0 index: Urlar
backlist 1 index: Urlar

Pero quiero esto:

backlist 0 index: Neoplazma
backlist 1 index: Urlar
¿Fue útil?

Solución

Es el mismo diccionario que estás imprimiendo. Necesitas crear uno nuevo para cada addObject:.

[self.backlist addObject:[NSMutableDictionary dictionaryWithDictionary:icdcodeDictionary]];

Otros consejos

Ok, tengo su problema mientras establece el diccionario dentro de Forloop, debe escribir como este código a continuación dentro de su bucle for.

// here it is for loop
 for (i=0; i<2; i++)
 {
 // this dictinary needs to call how many times   
 you set object
  NSMutableDictionary * mut= 
 [NSMutableDictionary dictionary];
 // now set your object inside dictionary
 }
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top