J'aime faire un tableau sur une structure typedef que j'ai.NSMutableArray avec Struct
Cela fonctionne très bien lorsque je travaille avec une taille de tableau FIXE. Mais juste pour être ouvert pour les tableaux plus grands, je suppose que je dois le faire avec le tableau nsmutable. Mais ici je n'obtenir courir
//------------ test STRUCT
typedef struct
{
int id;
NSString* picfile;
NSString* mp3file;
NSString* orgword;
NSString* desword;
NSString* category;
} cstruct;
//------- Test Fixed Array
cstruct myArray[100];
myArray[0].orgword = @"00000"; // write data
myArray[1].orgword = @"11111";
NSLog(@"Wert1: %@",myArray[1].orgword); // read data *works perfect
//------ Test withNSMutable
NSMutableArray *array = [NSMutableArray array];
cstruct data;
int i;
for (i = 1; i <= 5; i++) {
data.orgword = @"hallo";
[array addObject:[NSValue value:&data withObjCType:@encode(struct cstruct)]];
}
data = [array objectAtIndex:2]; // something is wrong here
NSLog(@"Wert2: %@",data.orgword); // dont work
une courte démonstration qui fonctionne serait apprécié :) apprendre encore
Thx Chris
Votre tableau retourne une instance de NSValue ... c'est ce que vous y mettez. Donc, pour lire: [[array objectAtIndex: 2] getValue: &data]; –
OK !! :) thx, maintenant ça marche :) –