图像未存储在NSMutableArray中

问题描述

我正在尝试将图像存储在NsMutable Array。但是在该功能中不起作用。但是最终在其他功能上它仍然可以正常工作。有人可以告诉我为什么它不起作用。
- (void)readplistData {

objectButtonArray = [[NSMutableArray alloc] init];   \\\\Use to store Buttons
editButtonArray = [[NSMutableArray alloc] init];      \\\\ another array use to store deletebutton(such as.crossmark button.)
selectimage = [[NSMutableArray alloc] init];

self.myPlistPath = [Nsstring stringWithString:[self plistPath]];

plistArray = [[NSMutableArray alloc] initWithContentsOfFile:self.myPlistPath];

for (int i =0; i< [plistArray count];i++)
{


    UIGraphicsEndImageContext();

    NSData *imageData = [plistArray objectAtIndex:i];
    currentObjectimage = [UIImage imageWithData:imageData] ; 
    [selectimage addobject:currentObjectimage]; \\\\value not stored in selectimage NSMutableArray

    CGRect imageSize = CGRectMake(0,100,90);

    UIGraphicsBeginImageContext(imageSize.size); // this will crop

    [currentObjectimage drawInRect:imageSize];

    UIImage* newImage = UIGraphicsGetimageFromCurrentimageContext();

    imageButton = [[UIButton alloc]initWithFrame:CGRectMake(width,90)];
    [imageButton setTag:tag];
    [imageButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
    [imageButton setimage:newImage forState:UIControlStatenormal];

    CGRect backFrame = backView.frame;
    backFrame.size.width = 120+width;
    backView.frame = backFrame;

    [backView addSubview:imageButton];

    editButton = [[UIButton alloc]initWithFrame:CGRectMake(width-10,-10,35,35)];
    [editButton setimage:[UIImage imageNamed:@\"DeleteButton.png\"] forState:UIControlStatenormal];
    [editButton addTarget:self action:@selector(deleteObjectViewImage:) forControlEvents:UIControlEventTouchUpInside];
    editButton.hidden = YES;
    [editButton setTag:tag];
    [backView addSubview:editButton];
    tag++;
    width = 120 + width;

    [objectButtonArray addobject:imageButton];
    [editButtonArray addobject:editButton];

}

scrollView.contentSize = backView.bounds.size;  
} 有人能帮我吗。     

解决方法

        我认为问题基本上是在执行时引用名称\“ currentObjectImage \”
[selectImage addObject:currentObjectImage];
它保存\“ currentObjectImage \”的引用,在该引用中,在下一次迭代中将下一个图像加载到其中,这会产生问题。 将上面的行替换为
[selectImage addObject:[currentObjectImage copy]];
我认为它将解决您的问题。