单击按钮时无法在 iPhone 中调用触摸事件
当我点击按钮时,我需要在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您没有 TouchBegan 的 @selector。相反,您可以将其用于 KeyboardRefresh。不要在 TouchsBegan 中检查按钮按下情况。相反,将 TouchBegan 替换为:
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: