0

please i try to put the content of two NSArray in two NSMutableArray but it seems not working :

NSMutableArray *newArrayTypeCarburant = [[NSMutableArray alloc]init];
    NSMutableArray *newArrayNomStation = [[NSMutableArray alloc]init];
    for(int i=0; i <[topStation.listeTypesDesCarburants count]; i++)
    {
        [newArrayTypeCarburant addObjectsFromArray: [topStation.listeTypesDesCarburants objectAtIndex:i]]; 
    }
    for(int i=0; i <[topStation.listeDesEnseignes count]; i++)
    {
        [newArrayNomStation addObjectsFromArray: [topStation.listeDesEnseignes objectAtIndex:i]]; 
    }

topStation.listeDesEnseignes and topStation.listeTypesDesCarburants are two NSArray and global variables declared in the appdelegate class . Help please, thx in advance ))

EDIT i try that :

NSMutableArray *newArrayTypeCarburant = [[NSMutableArray alloc]init];
    NSMutableArray *newArrayNomStation = [[NSMutableArray alloc]init];



    for(int i=0; i <[topStation.listeTypesDesCarburants count]; i++)
    {
        [newArrayTypeCarburant addObject: [topStation.listeTypesDesCarburants objectAtIndex:i]]; 
    }
    for(int i=0; i <[topStation.listeDesEnseignes count]; i++)
    {
        [newArrayNomStation addObject: [topStation.listeDesEnseignes objectAtIndex:i]]; 
    }
    self.pickerArrayTypeCarburant = newArrayTypeCarburant;
    self.pickerArrayNomStation = newArrayNomStation;

the first picker contains value from the array but when i try to click on the second picker, an exception was thrown :

2011-05-04 15:10:06.631[1065:207] -[__NSCFDictionary isEqualToString:]: unrecognized selector sent to instance 0x6e389a0
2011-05-04 15:10:06.633[1065:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary isEqualToString:]: unrecognized selector sent to instance 0x6e389a0'
0

2 Answers 2

2

You are using NSArray addObjectsFromArray: which will copy an entire array but you are doing it once for each container member (as well as not passing the correct type since it expects an NSArray ref and you're passing the individual elements). Instead try copying the arrays like this and remove the for-loops:

[newArrayTypeCarburant addObjectsFromArray: topStation.listeTypesDesCarburants];
[newArrayNomStation addObjectsFromArray: topStation.listeDesEnseignes];

If you still need to walk through them one at a time use the code you have but change addObjectsFromArray: to addObject::

for(int i=0; i <[topStation.listeTypesDesCarburants count]; i++)
{
    // perhaps some predicate here...
    [newArrayTypeCarburant addObject: [topStation.listeTypesDesCarburants objectAtIndex:i]]; 
}
Sign up to request clarification or add additional context in comments.

3 Comments

when i try to parse the second array, i have that : {"ssiphone_enseigne":"SHELL","0":"SHELL"},{"ssiphone_enseigne":"ELF","0":"ELF"},{"ssiphone_enseigne":"BP","0":"BP"},{"ssiphone_enseigne":"AGIP","0":"AGIP"},{"ssiphone_enseigne":"CARREFOUR","0":"CARREFOUR"},{"ssiphone_enseigne":"CASINO","0":"CASINO"},{"ssiphone_enseigne":"ESSO","0":"ESSO"},{"ssiphone_enseigne":"AUCHAN","0":"AUCHAN"},{"ssiphone_enseigne":"LECLERC","0":"LECLERC"},{"ssiphone_enseigne":"AVIA","0":"AVIA"},{"ssiphone_enseigne":"SUPER U","0":"SUPER U"},{"ssiphone_enseigne":null,"0":null},{"ssiphone_enseigne":"AUTRE","0":"AUTRE"}
However, in the web-service side the array is composed only of these elements : SHELL, ELF,BP, AGIP,CARREFOUR,CASINO,ESSO,AUCHAN,LECLERC,AV­IA,SUPER U,AUTRE
At first glance I would say you are trying to mix dictionaries with arrays.
1

you could just use arrayWithArray.

NSMutableArray *newArrayNomStation = [NSMutableArray arrayWithArray:topStation.listeDesEnseignes];

2 Comments

hi ok, but when i try to assign each array to a UIPicker i got that error in the log when execution : Program received signal: “EXC_BAD_ACCESS”. for this code : pickerArrayTypeCarburant = newArrayTypeCarburant; pickerArrayNomStation = newArrayNomStation;
Well that looks like a memory management issue. Something is getting released too soon.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.