I have a very strange issue in iOS.I have two classes AViewController & BViewController. In AViewController i am having an array like
@property NsmutableArray *array_one;
I am passing some data from one view controller to another in prepareforsegue method.
if([self.array_one count]>0)
{
viewBController.array_two=self.array_one;
}
then from BviewController i am passing back the data like this
-(void)viewWillDisappear:(BOOL)animated
{
int j;
[self.delegate setData:self.array_two];
}
Then i am in this method doing this work
- (void)setData:(NSMutableArray *)data
{
NSString *string=[NSString stringWithFormat:@"%lu",(long)[data count]];
[self.array_one removeAllObjects];
int i;
for(i=0;i<[string intValue];i++)
{
User *u=[data objectAtIndex:i];
[self.array_one addObject:u];
}
}
Now what happened is if go to view one controller to another 2 times in second time if i add this line [self.array_one removeAllObjects]; then my data array get empty.I don't know why?
Please guide me
NSString *string=[NSString stringWithFormat:@"%lu",(long)[data count]];and[string intValue]. Well done.setData:method, get rid of thestringvariable. Change yourforloop tofor (NSUInteger i = 0; i < data.count; i++). Better yet, replace the whole loop with just[self.array_one addObjectsFromArray:data];.