开发者

problem when trying to put the content of NSArray in NSMutableArray

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 'NSIn开发者_StackOverflow中文版validArgumentException', reason: '-[__NSCFDictionary isEqualToString:]: unrecognized selector sent to instance 0x6e389a0'


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]]; 
}


you could just use arrayWithArray.

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜