2011-06-04 27 views
0

我想将图像存储在NsMutable Array.But中,但它不能在该函数中工作。但最终在其他功能它正常工作。有人告诉我为什么它不工作。未存储在NSMutableArray中的图像

- (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, 0, 100, 90); 

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

    [currentObjectImage drawInRect:imageSize]; 

    UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext(); 

    imageButton = [[UIButton alloc]initWithFrame:CGRectMake(width, 0, 100, 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; 

}

有人可以帮助我。

+2

“不工作”是什么意思?这是一个编译器错误?运行时错误? plist没有被加载?图像是错误地创建的?根本没有图像?按钮不显示在视图上?请更具体地说 - 粘贴一些代码并说'不工作'是不好的形式。帮助我们帮助你! – 2011-06-04 08:29:58

回答

0

我认为这个问题是引用名为“currentObjectImage”基本上当你正在做

[selectImage addObject:currentObjectImage]; 

节省“currentObjectImage”,其中在下一次迭代下一个图像是它加载它创建问题的参考。

替换以上符合

[selectImage addObject:[currentObjectImage copy]]; 

我认为这将解决您的问题。