Iphone 从可变数组获取UIImageView

Iphone 从可变数组获取UIImageView,iphone,ios,objective-c,Iphone,Ios,Objective C,我将所有的电路板UIImageViews存储到一个可变数组中,“BRD”(相交的那些) 然后,我在brds中找到了右板,例如索引1:。然后我试着用BRD的位置来工作[1]。为什么我没有得到正确的x和y。我相信它总是给我x=0和y=0。左上角 board1 = brds[1]; CGRect frame = image.frame; frame.origin.x = board1.frame.origin.x; frame.origin.y = board1.frame.origin.y; im

我将所有的电路板
UIImageViews
存储到一个可变数组中,“BRD”(相交的那些)

然后,我在brds中找到了右板,例如索引1:。然后我试着用BRD的位置来工作[1]。为什么我没有得到正确的x和y。我相信它总是给我x=0和y=0。左上角

board1 = brds[1];

CGRect frame = image.frame;
frame.origin.x = board1.frame.origin.x;
frame.origin.y = board1.frame.origin.y;
image.frame = frame;

当我将imageview放入数组时,它不存储坐标吗?

它不是
board1=brds[1]

brds不是C数组,它是NSArray。使用
board1=[brds objectAtIndex:1]

您应该使用
NSLog
检查数组是否确实包含数据。它可能为空,您必须在添加对象之前对其进行初始化。

RGRect数据结构不是可重用的Objective-C对象。这意味着您不能修改它们。最简单的方法是为您的目的创建一个新的

CGRect frame = CGRectMake(board1.frame.origin.x,
                          board1.frame.origin.y,
                          image.frame.size.width,
                          image.frame.size.height);

image.frame = frame;

在for循环wihin if中,尝试记录并检查它打印的内容。您初始化了BRD吗?谢谢您尝试了这个,问题是我的addObject。它甚至没有在一开始就向BRD添加一个对象。嘿,我完全错过了。接得好。@Donny,问题出在你的交叉点查询中。它看起来不匹配。如果这不起作用,填充该BRD的正确方法是什么?需要使用[[NSMutableArray alloc]init]声明数组;它是固定的!谢谢
CGRect frame = CGRectMake(board1.frame.origin.x,
                          board1.frame.origin.y,
                          image.frame.size.width,
                          image.frame.size.height);

image.frame = frame;