【发布时间】:2010-09-10 13:06:45
【问题描述】:
我有一个名为 myPicture1、myPicture2 和 myPicture3 的三个 UIImageView 变量。在 for 循环中,我试图将 myPicture 末尾的数字增加 1,以便我可以为三个变量中的每一个分配一个随机图像。下面是代码:
for (i=0; i<3; i++) {
int g = arc4random() % 19;
NSString *imagename = [NSString stringWithFormat:@"image%d.jpg",g];
UIImage *picture = [UIImage imageNamed:imagename];
UIImageView imageView = [[UIImageView alloc] initWithImage : picture];
self.myPicture1 = imageView; **This is where I want myPicture to increase to myPicture 2 and then 3 **
}
这可能吗?
谢谢大家,
马丁
【问题讨论】:
-
如果你有
retain或copy属性,你并不是在泄漏imageView。你应该在调用属性设置器后release它。
标签: objective-c c xcode loops for-loop