I have a strange behavior with my buttons that I add to a scrollview.
for (UIView *subview in self.scrollView.subviews) {
[subview removeFromSuperview];
}
//Create and place info Button(s)
for (int i = 0; i < BigPictures.count; i++) {
UIButton *infoButton = [[UIButton alloc] initWithFrame:CGRectMake(scrollView.frame.size.width*(i+1) - 29 - 5 - 10, scrollView.frame.size.height - 29 - 5, 29, 29)];
[infoButton addTarget:self action:@selector(flip) forControlEvents:(UIControlEvents)UIControlEventTouchUpInside];
//[infoButton setEnabled:YES];
//[infoButton setUserInteractionEnabled:YES];
[self.scrollView addSubview:[FrontViews objectAtIndex:i]];
[infoButton setBackgroundImage:[UIImage imageNamed:@"btn_image-info.png"] forState:UIControlStateNormal];
[scrollView addSubview:infoButton];
BigPictures contains all images I want to show in the scrollview.
Now to the odd thing. If BigPictures contains 1 image then the action (flip) is called. As soon as [BigPictures count] > 1 then the button on the first image is not executing the action but all other buttons (page 2-n) are. So how can this be??
Even if I change for (int i = 0; i < BigPictures.count; i++) with for (int i = 0; i < 1; i++) then the button is working.
So what am I missing? Already tried things like
scrollView.delaysContentTouches = NO;
scrollView.canCancelContentTouches = NO;
but latter one disables scrolling of scrollview.
EDIT:
I tried placing other buttons at different positions and none of them work on the first page (if pages > 1). Also tried to place a GestureRecognizer. This works but if ([touch.view isKindOfClass:[UIButton class]]) is not detecting a button underneath. All works fine on the other pages in scrollview. Really weird.
Did a complete rebuild and now it works. Really strange because I used the exact same code.