0

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

请任何人让我知道如何解决这个问题。

按钮代码如下。

-(无效)方法{

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];

如果(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(@"是"); }

当我单击刷新按钮时没有调用。

谁能帮我吗。提前致谢

4

1 回答 1

1

您没有 touchesBegan 的 @selector。相反,您将它用于 KeyboardRefresh。不要在 touchesBegan 中检查按钮是否按下。而是将您的 touchesBegan 替换为:

-(void)KeyboardRefresh:(id) sender
{ 
    NSLog(@"yes");
}
于 2010-08-21T05:17:45.800 回答