Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.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
Objective c 是否将图像正确加载到现有故事板UIImageView中?_Objective C_Uiimageview - Fatal编程技术网

Objective c 是否将图像正确加载到现有故事板UIImageView中?

Objective c 是否将图像正确加载到现有故事板UIImageView中?,objective-c,uiimageview,Objective C,Uiimageview,我正在使用数组尝试将图像加载到特定的UIImageView中。我在故事板上设置了10个UIImageView 我还有一个Game-Over方法,每当一个UIImageView的帧与另一个UIImageView相交时都会运行。出于某种原因,每当我尝试使用数组加载UIImageView时,就会立即触发Game Over方法。我不明白为什么。只要我删除initWithImage行,游戏就会正常运行。有什么想法吗 - (void)viewDidLoad { KanaCharacters = [[NS

我正在使用数组尝试将图像加载到特定的UIImageView中。我在故事板上设置了10个UIImageView

我还有一个Game-Over方法,每当一个UIImageView的帧与另一个UIImageView相交时都会运行。出于某种原因,每当我尝试使用数组加载UIImageView时,就会立即触发Game Over方法。我不明白为什么。只要我删除initWithImage行,游戏就会正常运行。有什么想法吗

- (void)viewDidLoad
{
  KanaCharacters = [[NSArray alloc] initWithObjects:[UIImage imageNamed:@"a.png"],...
                  nil];


int imageDisplay = arc4random_uniform([KanaCharacters count]);

Monster1 = [[UIImageView alloc] initWithImage:[KanaCharacters objectAtIndex:imageDisplay]];
}

-(void) Collision
{
   if ((CGRectIntersectsRect(Monster1.frame, Ship.frame)) && (Monster1Hit==NO))
   {
      [self GameOver];
   }
}

-(void)GameOver
{
  WinOrLose.hidden=NO;
  WinOrLose.text = [NSString stringWithFormat:@"You Lose!"];
 }

我怀疑如果在Monster1和Ship.frame中发射一次图像,会发生碰撞。 这是因为我怀疑你的怪物被安置在你船所在的地方


在将图像添加到视图中之前,您可能需要移动飞船或怪物

很难理解代码片段中发生了什么,但如果您在故事板中有uiimageview(monster1在故事板中吗?),您就不应该在viewDidLoad中再次alloc&init。请改为调用setImage,否则您的新UIImageView甚至不会添加到viewcontroller的视图中,您需要使用addSubview手动添加它。是的,很抱歉,这有点难以解释。没错,Monster1已经是故事板中的ImageView。我也想过setImage,但它不是UIImageView的方法,只适用于UIImage。我是否应该将数组中的图像设置为UIImage,然后以某种方式将该变量用于UIImageView?(很抱歉,这是新的!)图像是的属性,因此您可以对其调用setImage,也可以调用monster1.image=[UIImage…]