Question

I am trying to store the locations of 10 UIImages I have stored within a UICollection and placed using the interface builder. I am trying to do so using View.center but all my CGPoints are returning as {0,0} when logged.

Another strange thing is I set up a break point on the for loop, two {0,0} values are returning prior to the loop beginning.

Code:

- (void)viewDidLoad
{
    dealerBtnOrigins = [[NSMutableArray alloc] init];
        NSValue *point;
        CGPoint cGPoint;
        for (int i = 0; i < 10; i++)
        {
            cGPoint = ((UIImageView *)[dealerBtns objectAtIndex:i]).center;
            point = [NSValue valueWithCGPoint:((UIImageView *)[dealerBtns objectAtIndex:i]).center];
            NSLog(@"%@", NSStringFromCGPoint(cGPoint));
            NSLog(@"%@", NSStringFromCGPoint(point.CGPointValue));
            [dealerBtnOrigins addObject:point];
        }
}
Was it helpful?

Solution

Your collectionView hasn't rendered yet in viewDidLoad. Place the code in viewWillAppear or viewDidAppear after you have created the collectionView for the coors to show.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top