I am developing one applciation.In that I need to display the 9 UIImageViews in another UIImageView.And if we click on any image then identify that selected UIImageView and change the image of that selected UIImageView.Next time also need to do the same but we need to display the previous selected image with new changed image.For that I written the code like
for (int h=0; h<8; h++)
{
int x=[[questions.marker_left objectAtIndex:h] intValue];
int y=[[questions.marker_top objectAtIndex:h] intValue];
img3=[[UIImageView alloc]initWithFrame:CGRectMake(x,y, 30, 30)];
img3.userInteractionEnabled=YES;
img1.userInteractionEnabled=YES;
img3.tag=h;
//img2.backgroundColor=[UIColor greenColor];
img3.image=[UIImage imageNamed:@"PINpurple.png"];
tap5=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(calculate:)];
tap5.delegate=self;
[img3 addGestureRecognizer:tap5];
[img1 addSubview:img3];
}
-(void)calculate:(UITapGestureRecognizer*)recognizer
{
NSInteger i=(recognizer).view.tag;
NSString *str=[questions.result objectAtIndex:i];
NSLog(@"%@",str);
if([str isEqualToString:@"true"])
{
img3.image=[UIImage imageNamed:@"PINgreen.png"];
}
else
{
img3.image=[UIImage imageNamed:@"PINred.png"];
}
}
The selected image will be changed but previous UIImageView will get the old image after selecting the next UIImageView.So please help me, how to do this?
1 Answer