2010-08-21 85 views
0

我需要在iPhone上点击按钮时调用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 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)]; 
} 

}

上述methos正在呼叫和

- (无效)的touchesBegan:(NSSet中*)触摸withEvent:方法(UIEvent *)事件

{ NSLog(@“yes”); }

当我点击刷新butotn时没有调用。

任何人都可以帮助我。 在此先感谢

回答

1

您没有用于touchesBegan的@selector。你可以将它用于KeyboardRefresh。不要检查touchesBegan中的按钮压力。取而代之的是你的触摸开始于:

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

Thankyou的消息。但我需要调用两者,而且我需要调用触摸移动和触摸结束是否有任何想法。当点击刷新按钮时它必须显示另一个按钮。 – Ganesh 2010-08-21 05:22:38

+0

我不确定,但是,如果你担心按钮,你可能只是想为不同的状态制作多种方法。即UIControlEventTouchUpInside – 2010-08-21 16:22:47