Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何将一系列类似的行转换为for循环?_Iphone_Objective C_For Loop_Foundation - Fatal编程技术网

Iphone 如何将一系列类似的行转换为for循环?

Iphone 如何将一系列类似的行转换为for循环?,iphone,objective-c,for-loop,foundation,Iphone,Objective C,For Loop,Foundation,我正在为iPhone编写一个应用程序。我还不太擅长循环。如何将此代码缩短为for循环 if(CGRectContainsRect([space1 frame], [box frame])){ space1.image = [UIImage imageNamed:@"box.png"]; } else if(CGRectContainsRect([space2 frame], [box frame])){ space2.image = [UIImage imageNamed:@"b

我正在为iPhone编写一个应用程序。我还不太擅长循环。如何将此代码缩短为for循环

if(CGRectContainsRect([space1 frame], [box frame])){

  space1.image = [UIImage imageNamed:@"box.png"];
 }
 else if(CGRectContainsRect([space2 frame], [box frame])){

  space2.image = [UIImage imageNamed:@"box.png"];
 }
 else if(CGRectContainsRect([space3 frame], [box frame])){

  space3.image = [UIImage imageNamed:@"box.png"];
 }
 else if(CGRectContainsRect([space4 frame], [box frame])){

  space4.image = [UIImage imageNamed:@"box.png"];
 }
 else if(CGRectContainsRect([space5 frame], [box frame])){

  space5.image = [UIImage imageNamed:@"box.png"];
 }

2错误,空格未声明,选择器元素没有有效的type@NextRev-检查你的大写字母。我准确地复制了它。还是说空间undeclared@NextRev那是因为我不知道什么样的物体。。。space5是,所以我刚组成了太空舱。换成他们应该是的任何类型。抱歉,我对这东西不熟悉,他们是UIImageView。我实际上是在尝试检测用户何时在不抬起手指的情况下将手指滑过这些UIImageView,并在它们经过每个UIImageView时执行代码。对于您提供的循环,这是一个复杂的问题还是有一行类似这样的代码?2个错误、未声明的空格和选择器元素没有有效的type@NextRev-检查你的大写字母。我准确地复制了它。还是说空间undeclared@NextRev那是因为我不知道什么样的物体。。。space5是,所以我刚组成了太空舱。换成他们应该是的任何类型。抱歉,我对这东西不熟悉,他们是UIImageView。我实际上是在尝试检测用户何时在不抬起手指的情况下将手指滑过这些UIImageView,并在它们经过每个UIImageView时执行代码。这是一个复杂的问题还是您提供的循环中有这样一行代码?
NSArray * spaces = [NSArray arrayWithObjects:space1, space2, space3, space4, space5, nil];
for (Space * space in spaces) {
  if (CGRectContainsRect([space frame], [box frame])) {
    space.image = [UIImage imageNamed:@"box.png"];
  }
}