单击按钮时无法在 iPhone 中调用触摸事件

发布于 2024-09-15 13:06:20 字数 1528 浏览 4 评论 0原文

当我点击按钮时,我需要在 iPhone 中调用触摸事件。 我有以下代码,未调用触摸事件

请任何人告诉我如何解决此问题。

按钮代码如下。

-(无效)方法 {

BottomView = [[UIView 分配] init];

btnRefresh =[UIButton buttonWithType:UIButtonTypeCustom]; [btnRefresh setImage:[UIImage imageNamed:@"refresh_icon.png"] forState:UIControlStateNormal]; [btnRefresh setBackgroundImage:[[UIImage imageNamed:@"blue.png"]stretchableImageWithLeftCapWidth:12.0 topCapHeight:0.0] forState:UIControlStateNormal]; [btnRefresh setBackgroundImage:[[UIImage imageNamed:@"ggrey1.png"]stretchableImageWithLeftCapWidth:12.0 topCapHeight:0.0] forState:UIControlStateHighlighted]; [btnRefresh setBackgroundImage:[[UIImage imageNamed:@"ggrey1.png"]stretchableImageWithLeftCapWidth:12.0 topCapHeight:0.0] forState: UIControlStateSelected]; [btnRefresh addTarget:self 操作:@selector(KeyboardRefresh:) forControlEvents:UIControlEventTouchUpInside];
[btnRefresh setUserInteractionEnabled:YES]; [btnRefresh setMultipleTouchEnabled:YES];

[BottomView addSubview:btnRefresh];

if (self.isPortrait) {

    [btnRefresh setFrame:CGRectMake(71, 0, 40, 6)];

    [BottomView setFrame:CGRectMake(0, 160, 320, 41)];
}
else{

    [btnRefresh setFrame:CGRectMake(94, 0, 61, 8)];

    [BottomView setFrame:CGRectMake(0, 123, 480, 41)];
}

}

正在调用上述方法并且

-(void) TouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

{ NSLog(@"是"); 。

当我点击刷新按钮时,没有调用

任何人都可以帮我吗? 提前致谢

i need to call touch event in iphone when i clicked on a button.
i have the following code which is not calling touch event

Please any one let me know how to resolve this.

The button code is as follows.

-(void)method
{

BottomView = [[UIView alloc] init];

btnRefresh =[UIButton buttonWithType:UIButtonTypeCustom];
[btnRefresh setImage:[UIImage imageNamed:@"refresh_icon.png"] forState:UIControlStateNormal];
[btnRefresh setBackgroundImage:[[UIImage imageNamed:@"blue.png"] stretchableImageWithLeftCapWidth:12.0 topCapHeight:0.0] forState:UIControlStateNormal];
[btnRefresh setBackgroundImage:[[UIImage imageNamed:@"ggrey1.png"]stretchableImageWithLeftCapWidth:12.0 topCapHeight:0.0] forState:UIControlStateHighlighted];
[btnRefresh setBackgroundImage:[[UIImage imageNamed:@"ggrey1.png"] stretchableImageWithLeftCapWidth:12.0 topCapHeight:0.0] forState: UIControlStateSelected];
[btnRefresh addTarget:self action:@selector(KeyboardRefresh:) forControlEvents:UIControlEventTouchUpInside];
[btnRefresh setUserInteractionEnabled:YES];
[btnRefresh setMultipleTouchEnabled:YES];

[BottomView addSubview:btnRefresh];

if (self.isPortrait) {

    [btnRefresh setFrame:CGRectMake(71, 0, 40, 6)];

    [BottomView setFrame:CGRectMake(0, 160, 320, 41)];
}
else{

    [btnRefresh setFrame:CGRectMake(94, 0, 61, 8)];

    [BottomView setFrame:CGRectMake(0, 123, 480, 41)];
}

}

the above methos is calling and the

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

{
NSLog(@"yes");
}

is not calling when i click on refresh butotn.

can any one help me out.
Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

铃予 2024-09-22 13:06:20

您没有 TouchBegan 的 @selector。相反,您可以将其用于 KeyboardRefresh。不要在 TouchsBegan 中检查按钮按下情况。相反,将 TouchBegan 替换为:

-(void)KeyboardRefresh:(id) sender
{ 
    NSLog(@"yes");
}

You don't have the @selector for touchesBegan. You instead have it for KeyboardRefresh. Don't check for button pressage in touchesBegan. Instead replaces your touchesBegan with:

-(void)KeyboardRefresh:(id) sender
{ 
    NSLog(@"yes");
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文