开发者

Converting a CGRect to an NSValue in an Array and vice versa

I have an array, full of CGRects. That part is fine. The problem is when I go to retrieve the CGRects from the array, I'm getting weird errors. Check out my code.

NSArray *frameLocations = [NSArray arrayWithObjects:
                           [NSValue valueWithCGRect:CGRectMake(20, 20, 121, 124)],
                           [NSValue valueWithCGRect:CGRectMake(176, 20, 12开发者_如何转开发1, 124)],
                           nil];

Than I get the frame in a for loop, like this:

 CGRect *imageFrame = [[frameLocations objectAtIndex:i] CGRectValue];

I've tried a bunch of different variations, spreading that line out over multiple variables. But I can't seem to get it.


Try:

CGRect imageFrame = [[frameLocations objectAtIndex:i] CGRectValue];

You get an actual CGRect back, not a pointer to a CGRect, because it's a primitive C-style type, not an Objective-C object.

Apart from that your code looks correct.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜