Pour une raison quelconque, le bouton initialisé dans la méthode addBook de mon viewController ne répondra pas aux touches. Le sélecteur que je lui ai assigné ne se déclenche jamais, et l'image UIControlStateHighlighted n'apparaît jamais lorsque vous appuyez sur l'image.iPhone: ajouter un bouton pour faire défiler la vue rend le bouton inaccessible à l'interaction
Y at-il quelque chose d'interception touche avant de se rendre à la UIButton, ou est son interactivité en quelque sorte désactivé par ce que je fais à elle?
- (void)viewDidLoad {
...
_scrollView.contentSize = CGSizeMake(currentPageSize.width, currentPageSize.height);
_scrollView.showsHorizontalScrollIndicator = NO;
_scrollView.showsVerticalScrollIndicator = NO;
_scrollView.scrollsToTop = NO;
_scrollView.pagingEnabled = YES;
...
}
- (void)addBook {
// Make a view to anchor the UIButton
CGRect frame = CGRectMake(0, 0, currentPageSize.width, currentPageSize.height);
UIImageView* bookView = [[UIImageView alloc] initWithFrame:frame];
// Make the button
frame = CGRectMake(100, 50, 184, 157);
UIButton* button = [[UIButton alloc] initWithFrame:frame];
UIImage* bookImage = [UIImage imageNamed:kBookImage0];
// THIS SECTION NOT WORKING!
[button setBackgroundImage:bookImage forState:UIControlStateNormal];
UIImage* bookHighlight = [UIImage imageNamed:kBookImage1];
[button setBackgroundImage:bookHighlight forState:UIControlStateHighlighted];
[button addTarget:self action:@selector(removeBook) forControlEvents:UIControlEventTouchUpInside];
[bookView addSubview:button];
[button release];
[bookView autorelease];
// Add the new view/button combo to the scrollview.
// THIS WORKS VISUALLY, BUT THE BUTTON IS UNRESPONSIVE :(
[_scrollView addSubview:bookView];
}
- (void)removeBook {
NSLog(@"in removeBook");
}
La hiérarchie de vue ressemble à ceci dans Interface Builder:
UIWindow
UINavigationController
RootViewController
UIView
UIScrollView
UIPageControl
et probablement comme celui-ci une fois la méthode addBook fonctionne:
UIWindow
UINavigationController
RootViewController
UIView
UIScrollView
UIView
UIButton
UIPageControl
Merci, Monsieur Marge. Cette dernière suggestion a fonctionné. – clozach
userInteractionEnabled était NON pour la vue à laquelle j'ajoutais UIButton en tant que sous-vue. C'était la cause, pas les 2 autres paramètres. – Alyoshak