无法点击UIButton iphone

时间:2012-06-19 08:15:33

标签: ios uitableview uiview uibutton

我正在tableview上创建UIView,其中会有一个imageview,最重要的是会有几个按钮。点击更改按钮(导航栏)时将显示此UiView。我已经以编程方式添加了所有内容。但是我无法点击UIView中存在的botton

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

}

2 个答案:

答案 0 :(得分:3)

默认情况下,userInteractionEnabledUIImageView的属性设置为NO。只需创建imageView.userInteractionEnabled = YES;即可。

答案 1 :(得分:0)

天哪啊。你可以将imageView的userInteractionEnabled设置为YES,然后在imageView中添加的按钮将响应click事件。

imageView.userInteractionEnabled = YES;