2013-02-03 95 views
0

我已經在我的iPhone應用程序中使用此代碼創建一個UIButton編程相同的UIButton:鏈接兩個事件來

UIButton *button = [UIButton   buttonWithType:UIButtonTypeRoundedRect]; 
[button addTarget:self 
     action:@selector(aMethod:) 
forControlEvents:UIControlEventTouchDown]; 
[button setTitle:@"Show View" forState:UIControlStateNormal]; 
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0); 
[view addSubview:button]; 

現在我想做的是:當我觸摸一下此鍵(第一動作)來顯示一個隱藏的標籤,當我釋放它時,它會將我帶到另一個視圖(第二個操作)。 有沒有人可以幫助我解決這個問題。 謝謝。

回答

4

試試這個

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
[button addTarget:self action:@selector(buttonTouchDown:) forControlEvents:UIControlEventTouchDown]; 
[button addTarget:self action:@selector(buttonTouchUp:) forControlEvents:UIControlEventTouchUpInside]; 
[button addTarget:self action:@selector(buttonTouchUpOutside:) forControlEvents:UIControlEventTouchUpOutside]; 


- (void) buttonTouchDown:(id) sender 
{ 
    //show hidden label 
} 

- (void) buttonTouchUp:(id) sender 
{ 
    //hide hidden label 
    //goto second view 
} 
- (void) buttonTouchUpOutside:(id) sender 
{ 
    //hide hidden label 
}