试图在我的老虎机iPhone应用程序中加载图像但收到错误(NSInvalidArgumentException)

时间:2011-08-22 13:30:55

标签: objective-c xcode uiimage

我是Xcode / objective-c洞的新手,所以我会以一种我能理解你的方式来回答我的问题:) 我的问题是:我正在尝试创建一个带拾取器和按钮的老虎机(当然要旋转轮子;))所以我实现了5个图像(苹果,皇冠,樱桃,柠檬,七,香蕉)但是在我启动应用程序时,我收到此错误:

  

由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:' - [UIImage initWithImage:]:无法识别的选择器发送到实例0x4b649b0'

我的代码如下所示:

- (void)viewDidLoad {
UIImage *apple = [UIImage imageNamed:@"apple.png"];
UIImage *banana = [UIImage imageNamed:@"banana.png"];    
UIImage *cherry = [UIImage imageNamed:@"cherry.png"];
UIImage *crown = [UIImage imageNamed:@"crown.png"];
UIImage *lemon = [UIImage imageNamed:@"lemon.png"];
UIImage *seven = [UIImage imageNamed:@"seven.png"];    

for (int i = 1; i <= 5; i++) {
    UIImageView *appleView = [[UIImage alloc] initWithImage:apple];
    UIImageView *bananaView = [[UIImage alloc] initWithImage:banana];    
    UIImageView *cherryView = [[UIImage alloc] initWithImage:cherry];    
    UIImageView *crownView = [[UIImage alloc] initWithImage:crown];   
    UIImageView *lemonView = [[UIImage alloc] initWithImage:lemon];   
    UIImageView *sevenView = [[UIImage alloc] initWithImage:seven];    

    NSArray *imageViewArray = [[NSArray alloc] initWithObjects:appleView, bananaView, cherryView, crownView, lemonView, sevenView, nil];

    NSString *fieldName = [[NSString alloc] initWithFormat:@"column%d", i];
    [self setValue: imageViewArray forKey:fieldName];
    [fieldName release];
    [imageViewArray release];
    [appleView release];
    [bananaView release];
    [cherryView release];
    [crownView release];
    [lemonView release];
    [sevenView release];

我一直在寻找打字错误很长一段时间,但没有发现任何问题。如果有人能给我一个提示,那将是非常好的。如果支持的代码不够,请随时提出更多要求。(只是复制了发生错误的部分)抱歉我的英文不好但不是我的母语:)

/ edit:我应该说,原来的错误是:SIGABRT,但看起来这个错误似乎意味着很多没有任何上下文:)

1 个答案:

答案 0 :(得分:2)

您需要使用

创建图片视图
[[UIImageView alloc] initWithImage: ...]

不是

[[UIImage alloc] initWithImage: ...]
相关问题