无法单击 UIButton iphone
Posted
技术标签:
【中文标题】无法单击 UIButton iphone【英文标题】:Not able to click UIButton iphone 【发布时间】:2012-06-19 08:15:32 【问题描述】:我在 tableview 之上创建 UIView,其中将有一个 imageview,并且在此之上将有几个按钮。当点击更改按钮(导航栏)时,将显示此 UiView。我已经以编程方式添加了所有内容。但我无法点击 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;
【问题讨论】:
【参考方案1】:UIImageView
中userInteractionEnabled
的属性默认设置为NO
.. 只需设置imageView.userInteractionEnabled = YES;
即可。
【讨论】:
【参考方案2】:天哪。只需将imageView的userInteractionEnabled设置为YES,然后imageView中添加的按钮就会响应点击事件。
imageView.userInteractionEnabled = YES;
【讨论】:
以上是关于无法单击 UIButton iphone的主要内容,如果未能解决你的问题,请参考以下文章
在 UITableViewCell 中无法点击 UIButton