按钮动作不能在iPhone上工作? [英] Button action not working in iphone?

查看:103
本文介绍了按钮动作不能在iPhone上工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个IPhone应用程序,我在其中添加自定义视图,尽管导航栏视图。我正常情况下隐藏自定义视图并在需要时取消隐藏它。现在我添加一个按钮到该自定义视图一个动作。但是当我点击它时,没有动作正在工作。任何人都可以帮助我吗?这是我在视图中的代码片段didload`

I have an IPhone application in which i am adding a custom view inspite of a navigation bar view.i am hiding that custom view in the normal case and unhide it whenever needed.now i am adding a button to that custom view having an action .but when i am clicking on it there is no action is working.can anybody help me?here is my code snippet in the view didload`

curtainsView=[[UIImageView alloc]init];
curtainsView.image=[UIImage imageNamed:@"curtains.png"];
curtainsView.frame=CGRectMake(0,-44, 320, 60);
curtainsView.backgroundColor=[UIColor clearColor];
UIImage *button2Image = [UIImage imageNamed:@"scroll_down.png"];
scroll = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
self.scroll.tag=100;
[scroll setImage:button2Image forState:UIControlStateNormal];
self.scroll.frame = CGRectMake(270,0, 40,40);
[scroll addTarget:self action:@selector(backpressed:) forControlEvents:UIControlEventTouchUpInside]; 
[self.curtainsView addSubview:scroll];
[self.view addSubview:curtainsView];
[self changeNavigationBarTitleTo:@""];
[curtainsView setHidden:YES];


推荐答案

您必须启用windowsView的用户交互。

You have to enable user interaction of curtainsView.

试试这个:

[curtainsView setUserInteractionEnabled:YES]

来自Apple的 UIImageView类参考


新图像视图对象配置为默认情况下忽略用户事件。如果要处理UIImageView的自定义子类中的事件,则必须在初始化对象后显式将userInteractionEnabled属性的值更改为YES。

New image view objects are configured to disregard user events by default. If you want to handle events in a custom subclass of UIImageView, you must explicitly change the value of the userInteractionEnabled property to YES after initializing the object.

这篇关于按钮动作不能在iPhone上工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆