Question

i m new to ios I am using a nsvalue to get frame of image view in a Array. but when i log the count of array it says only 1. I am using this array to somewhere else to retrieve the frames. Can you please tell me how i can get the array count as the number of image views number.

int j;
for (j=0; j<6; j++)
{
    UIImageView *imageView = [_imageArray objectAtIndex:j];
    array = [[NSMutableArray alloc]init];
    [array addObject:[NSValue valueWithCGRect:imageView.frame]];
    NSLog(@"%d",[array count]);
}
Was it helpful?

Solution

You are re-allocating (thus clearing all it's contents) your array each time you go trough the loop.

array = [[NSMutableArray alloc]init];

int j;
for (j=0; j<6; j++)
{
    UIImageView *imageView = [_imageArray objectAtIndex:j];

    [array addObject:[NSValue valueWithCGRect:imageView.frame]];
    NSLog(@"%d",[array count]);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top