ios - Adding items to a NSMutableArray - Logic issue -
i have 5 animal objects , trying save in nsmutabledictionary
. however, according code below, last animal gets saved in nsmutabledictionary
.
i don't think looping
correctly.
for(int = 0; < animalcount; i++) { [allcontacts setobject:name forkey:@"name"]; [allcontacts setobject:age forkey:@"age"]; [allcontacts setobject:gender forkey:@"gender"]; }
the output of above displays follows: (only last animal object gets displayed)
{ name = fish; age = 6; gender = "female"; }
how want that, 5 animal objects saved in nsmutabledictionary
can display them in uitableview
.
{ name = "cow"; age = 4; gender = "male"; }, { name = "dog"; age = 15; gender = "male"; }, { name = "fish"; age = 6; gender = "female"; }
key of nsmutabledictionary
unique.
what want build array , every object of array dictionary
nsmutablearray * contentsarray = [[nsmutablearray alloc] init]; for(int = 0; < animalcount; i++) { nsmutabledictionary * allcontacts = [[nsmutabledictionary alloc] init]; [allcontacts setobject:name forkey:@"name"]; [allcontacts setobject:age forkey:@"age"]; [allcontacts setobject:gender forkey:@"gender"]; [contentsarray addobject:allcontacts]; }
Comments
Post a Comment