我有 5 张图片,我想添加到数组中
代码:
#import "ViewController.h"
UIImageView *pic;
NSMutableArray *picArray;
@interface ViewController ()
@property (nonatomic, strong) NSMutableArray *picArray;
@end
@implementation ViewController
@synthesize picArray;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
picArray = [[NSMutableArray alloc] init];
pic = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 50, 75)];
pic.image = [UIImage imageNamed:@"pic1.png"];
pic.center = CGPointMake(100, 110);
[picArray addObject:pic];
pic.image = [UIImage imageNamed:@"pic2.png"];
pic.center = CGPointMake(100, 120);
[picArray addObject:pic];
pic.image = [UIImage imageNamed:@"pic3.png"];
pic.center = CGPointMake(100, 130);
[picArray addObject:pic];
pic.image = [UIImage imageNamed:@"pic4.png"];
pic.center = CGPointMake(100, 140);
[picArray addObject:pic];
pic.image = [UIImage imageNamed:@"pic5.png"];
pic.center = CGPointMake(100, 150);
[picArray addObject:pic];
pic = [picArray objectAtIndex:0];
pic.center = CGPointMake(200, 100);
[self.view addSubview:pic];
}
当我构建并运行此代码时,无论索引如何,我都只看到数组的最后一张图片 pic5.png
当我在数组中使用 NSString 时一切正常,但在我使用图像时没有(