我有一个带有 10 个 IBOutlet 图像的 UIViewController,我有一个图像,我想根据我的 i 在 for 循环中显示它我的意思是如果我的 i 等于 3 则将 img1、img2、img3 放在视图中
这是我的代码,我的问题是我无法显示它,请你告诉我是什么问题,提前谢谢!
@property (strong, nonatomic) IBOutlet UIImageView *img1;
@property (strong, nonatomic) IBOutlet UIImageView *img2;
@property (strong, nonatomic) IBOutlet UIImageView *img3;
@property (strong, nonatomic) IBOutlet UIImageView *img4;
- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:YES];
NSLog(@"Card description : %@", [_card description]);
int stampNumber = [_card.stampNumber intValue];
int i = 0;
UIImage *stampIMG = [UIImage imageNamed:@"1.jpg"];
NSLog(@"StampNumber : %i", stampNumber);
for (i = 0; i < stampNumber; i++) {
NSLog(@"i = %i", i);
switch (i)
{
case 0:
[_img1 setImage:stampIMG];
NSLog (@"one");
break;
case 1:
[_img2 setImage:stampIMG];
NSLog (@"two");
break;
case 2:
[_img3 setImage:stampIMG];
NSLog (@"three");
break;
case 3:
[_img4 setImage:stampIMG];
NSLog (@"four");
break;
case 4:
[_img5 setImage:stampIMG];
NSLog (@"five");
break;
case 5:
[_img6 setImage:stampIMG];
NSLog (@"six");
break;
case 6:
[_img7 setImage:stampIMG];
NSLog (@"seven");
break;
case 7:
[_img8 setImage:stampIMG];
NSLog (@"eight");
break;
case 8:
[_img9 setImage:stampIMG];
NSLog (@"nine");
break;
case 9:
[_img10 setImage:stampIMG];
NSLog (@"ten");
break;
default:
NSLog (@"test");
break;
}
}
}
这是我的日志:
StampNumber : 5
2013-03-18 14:14:31. i = 0
2013-03-18 14:14:31. one
2013-03-18 14:14:31. i = 1
2013-03-18 14:14:31. two
2013-03-18 14:14:31. i = 2
2013-03-18 14:14:31. three
2013-03-18 14:14:31. i = 3
2013-03-18 14:14:31. four
2013-03-18 14:14:31. i = 4
2013-03-18 14:14:31. five