2010-08-21 67 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