문제

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];
        }
}
도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top