iPhone: ajout de bouton pour le scrollview rend bouton inaccessibles à l'interaction

Pour une raison quelconque, le bouton initialisé dans le addBook méthode de mon viewController ne réagissent pas à la touche. Le sélecteur j'ai assigné à jamais déclenche, ni la UIControlStateHighlighted image apparaissent lorsque vous appuyez sur l'image.

Est là quelque chose de l'interception de touche avant d'arriver à la UIButton, ou est son interactivité en quelque sorte désactivé par ce que je fais?

- (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");
}

Le point de vue de la hiérarchie ressemble à ceci dans Interface Builder:

UIWindow
UINavigationController
    RootViewController
        UIView
            UIScrollView
            UIPageControl

et sans doute comme cela une fois la addBook méthode fonctionne:

UIWindow
UINavigationController
    RootViewController
        UIView
            UIScrollView
                UIView
                    UIButton
            UIPageControl

OriginalL'auteur clozach | 2010-03-01