错误:可能未初始化可变大小的对象.但为什么? [英] Error: Variable-sized object may not be initialized. But why?

查看:69
本文介绍了错误:可能未初始化可变大小的对象.但为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

enter code hereint quantity = [array count];
int i;
for (i=0; i<quantity; i++) 
{
    NSString *imageName = [NSString stringWithFormat:@"Car_%@.jpg",  [[array objectAtIndex:i] objectForKey:@"CarName"]]   ];
    UIImage *img[i] = [UIImage imageNamed:imageName];
    UIImageView *imgView[i] = [[UIImageView alloc] initWithImage:img[i]];
    imgView[i].frame = CGRectMake(i*kWidth, 0, kWidth, kHeight);
    [scrollView addSubview:imgView[i]];
    [imgView[i] release];
}`enter code here`

错误:可能未初始化可变大小的对象.但为什么?

Error: Variable-sized object may not be initialized. But why?

推荐答案

你可能想试试这个:

int i;
for (i=0; i<quantity; i++) 
{
    NSString *imageName = [NSString stringWithFormat:@"Car_%@.jpg",  [[array objectAtIndex:i] objectForKey:@"CarName"]]   ];
    UIImage *img = [UIImage imageNamed:imageName];
    UIImageView *imgView = [[UIImageView alloc] initWithImage:img];
    imgView.frame = CGRectMake(i*kWidth, 0, kWidth, kHeight);
    [scrollView addSubview:imgView];
    [imgView release];
}

您不需要使用 img[i] 来使用 UIImageView 填充滚动视图.

You don't need to use img[i] in order to populate a scrollview with UIImageView.

这篇关于错误:可能未初始化可变大小的对象.但为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆