2011-07-10 30 views
2

我有一個touchesBegan:方法,它工作正常。不過,我最近添加了一個UIView(一個按鈕)到我的UIViewController,現在該按鈕沒有註冊水龍頭,但我的方法是touchesBegan:touchesBegan - iPhone應用程序UIView

如何告訴我的touchesBegan:方法以避免按鈕?

這裏是我當前touchesBegan:方法:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
    NSLog(@"touches began"); 
    UITouch *touch = [touches anyObject]; 
    switch ([touch tapCount]) 
    { 
     case 1: 
      break; 

     case 2: 
      if(something) 
       [doing something]; 

      break; 

     default: 
      break; 
    } 
} 
+0

與往常一樣,仔細檢查以確保您已正確連接了IB中的按鈕,如果您是在IB中創建的。 –

回答

1

確保按鈕在前面([self.view bringSubviewToFront: myButton])。然後,您可以詢問在其中發生的觸摸:

if ([touch.view isEqualTo: myButton]) { 
    NSLog(@"touch was on button"); 
} 
0

我遇到了同樣的問題。當我將按鈕移動到前面時(通過UIViewController.bringSubviewToFront在代碼中),當點擊按鈕時touchesBegan不再被觸發。我在模擬器中運行Xcode 4.2。