i have a scrollview which has images added as subviews. i need to be able to select or tap on the images. in other words capture the name of the image tapped. please see my code below.
for (j = 1; j <= 12; j++)
{
NSString *imageName = [NSString stringWithFormat:@"%@",[months objectAtIndex:j-1]];
NSLog(@"imagename is %@",imageName);
UIImage *image = [UIImage imageNamed:imageName];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
CGRect rect = imageView.frame;
rect.size.height = smallScrollObjHeight;
rect.size.width = smallScrollObjWidth;
imageView.frame = rect;
imageView.tag = j;
[smalltapRecognizer setNumberOfTapsRequired:1];
[smalltapRecognizer setDelegate:self];
[imageView addGestureRecognizer:smalltapRecognizer];
[smalltapRecognizer release];*/
NSLog(@"tag value is %d ",imageView.tag);
[monthscroll addSubview:imageView];
[imageView release];
}
[self layoutsmallScrollImages];
UITapGestureRecognizer *smalltapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(smalltapped:)];
[smalltapRecognizer setNumberOfTapsRequired:1];
[smalltapRecognizer setDelegate:self];
[monthscroll addGestureRecognizer:smalltapRecognizer];
[smalltapRecognizer release];
//—————————-
-(void)smalltapped:(id)sender
{
NSLog(@”tapped”);
//Need to know how to proceed from here.
}
my program detects the tap and prints the tap log in the smalltapped function. i need to know how can i capture the name of the images selected or tapped on.
Why don’t you just use UIButtons in your scrollView instead? That way you can use the standard UIButton methods, don’t need to bother with gesture recognizers, and you’ll be able to see the image on the button being pressed.