如何解决图像未存储在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]];
我认为它将解决您的问题。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。