I have a NSMUtableArray where I want to insert at different index and in different method some data. So I initialize my NSMutableArray in my viewDidLoad like this:
- (void)viewDidLoad
{
[super viewDidLoad];
params=[[NSMutableArray alloc]init];
params =[NSMutableArray arrayWithCapacity:20];
for (int i = 0; i<20; i++) {
[params addObject:[NSNull null]];
}
}
And in different method I try to replace the null value by the real value:
-(void)doInBackGround{
NSString * domaine=@"Toto";
int port =8080;
[params replaceObjectAtIndex:8 withObject:domaine];
[params replaceObjectAtIndex:9 withObject:[NSString stringWithFormat:@"%d",nbPort]];
}
Another method where I try to replace the value in the NSMutableArray "params"
-(void)someMethod{
NSString * computer=@"Ajax";
int port =3333;
[params replaceObjectAtIndex:4 withObject:computer];
[params replaceObjectAtIndex:5 withObject:[NSString stringWithFormat:@"%d",nbPort]];
}
But I have a crash in line where I try to replace the Object:
[params replaceObjectAtIndex:8 withObject:domaine];
How can I fix It?. I think that my problem is where I intialize the NSMUtableArray? What do you think?