无法加载UIImageView

时间:2016-01-25 22:33:37

标签: ios objective-c iphone uiimageview nib

我一直在按照“学习目标-C开发iPhone游戏”一书的方式向外国人入侵者发出指示。

我在.m文件中输入了以下代码,然后该书告诉我运行以下代码:

@interface GameViewController ()
    @property (strong) UIImage *playerImage;
    @property (strong) UIImageView *playerView;
@end


@implementation GameViewController

    - (void)viewDidLoad {
        [super viewDidLoad];

        //Assign an image to a variable
        self.playerImage = [UIImage imageNamed:@"ship.png"];

        //Create an image view and start it up with out image
        self.playerView = [[UIImageView alloc] initWithImage: self.playerImage];

         //Set the image views bounding rectangle to scale the image.
         self.playerView.frame = CGRectMake(50,400, 32,32);

         //Show the image on the screen.
         [self.view addSubview: self.playerView];
     }
}

我尝试在模拟器中运行代码,但是会发生以下错误。为什么会这样?

Alien-Invaders[565:10012] Could not load the "backdrop.png" image referenced from a nib in the bundle with identifier "Chris.Alien-Invaders"

2 个答案:

答案 0 :(得分:0)

听起来如果你查看界面文件 - 有一个元素引用“backdrop.png”。您需要添加图像或删除引用它的元素。

答案 1 :(得分:0)

请检查截图,当您将backdrop.png拖到Xcode项目时,您会看到这些屏幕,请点击复制项目如果需要完成按钮将图像复制到您的Xcode项目 enter image description here