user1288005
user1288005

Reputation: 920

Not able to click UIButton iphone

I am creating UIView on top of tableview in which there will an imageview and on top of that there will be few buttons. This UiView will be shown when Change button(Navigation bar) is tapped. I have added everything programmtically. But i am not able to tap botton that are present in UIView

-(IBAction)changeViewController:(id)sender {
    if(!isViewShowing){
        NSLog(@"show Imageview");
        viewContainer = [[UIView alloc] initWithFrame: CGRectMake ( 276, 2, 40, 230)];
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 40, 230)];
        [imageView setImage:[UIImage imageNamed:@"bar.png"]];
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button addTarget:self action:@selector(buttonPressedAction:)forControlEvents:UIControlEventTouchUpInside];
        //[button setTitle:@"Show View" forState:UIControlStateNormal];
        button.frame = CGRectMake(0.0, 25.0, 36.0, 36.0);
        [button setBackgroundImage:[UIImage imageNamed:@"OLFB icon.png"] forState:UIControlStateNormal];

        [imageView addSubview:button];
        //[imageView release];
        [viewContainer addSubview: imageView];

        [self.view addSubview:viewContainer];
        [self.view bringSubviewToFront:button];
        //[polygonView release];
        isViewShowing=YES;
    }
    else 
    {
        NSLog(@"view not showing");
        [viewContainer removeFromSuperview];
        isViewShowing=NO;
    }

}

Upvotes: 0

Views: 1898

Answers (2)

Siam
Siam

Reputation: 109

Oh my god. you can just set the userInteractionEnabled of the imageView to YES, and then the button added in the imageView will response to the click event.

imageView.userInteractionEnabled = YES;

Upvotes: 0

Malek_Jundi
Malek_Jundi

Reputation: 6160

The property of userInteractionEnabled in UIImageView is set to NO by default .. just make the imageView.userInteractionEnabled = YES; and it will work.

Upvotes: 3

Related Questions