I am having an issue with TTImagViews inside UIScrollview. I searched high and low, but coul’dnt really find a solution. Interestingly, the tap gesture works on the last TTImageview inside the scrollview. For instance i have 10 images, that the user can scroll and the touch gesture works only on the 10th image on page 2 or rather, the last image. This is my code; any suggestions?
UIScrollView *imageScroll=[[UIScrollView alloc] initWithFrame:CGRectMake(70, postMessageLabel.frame.size.height+10, 250, 78)];
[imageScroll setContentSize:CGSizeMake(70 * ([[images objectAtIndex:0]count])+10,64)];
int startAtX=5;
for(int i=0;i<[[images objectAtIndex:0]count];i++){
if([[GlobalFunctions sharedGlobalFunctions] isValidURL:[[images objectAtIndex:0] objectAtIndex:i]]){
TTImageView *imageView=[[TTImageView alloc] initWithFrame:CGRectMake(startAtX, 5, 64, 64)] ;
imageView.userInteractionEnabled=YES;
[imageView addGestureRecognizer:thumbnailTap];
imageView.urlPath=[[images objectAtIndex:0] objectAtIndex:i];
imageView.autoresizesToImage=NO;
imageView.defaultImage=nil;
imageView.delegate=self;
[imageView setBackgroundColor:[UIColor blackColor]];
[imageScroll addSubview:imageView];
[imageView release];
}
startAtX+=70;
}
[imageScroll setBounces:YES];
[imageScroll setDelaysContentTouches:YES];
[imageScroll setCanCancelContentTouches:NO];
[self.view addSubview:imageScroll];
[imageScroll release];
And yeah, the tap gesture works perfectly if there is only one ttimageview inside the uiscrollview. I have no clue why!
Well, Looks’ like there is nothing wrong with my code; the only difference is how i am attaching the gesture recognizer. Even though i fixed i am not sure about why it went wrong. This is what happened
Step 2; seemed to be the problem. The problem went away when i declared a gesture recognizer for each and every image and released it after assigning it.
So technically for each image
That solved the problem. But am still curious, why the gesture recognizer works when assigned to a single and image and fails when i assign it to multiple imageviews.
Thanks Abdullah for trying, but your solution got me nowhere.