2011-03-29 85 views
1

我如何判斷在視圖中點擊了哪個按鈕? 單擊UIButton時是否有捕獲事件的「方面」方式?如何攔截按鈕水龍頭?

基本上,沒有任何額外的代碼,我可以捕獲所有的按鈕點擊。

回答

0

不確定的看法,但在一個視圖控制器,你可以指定與模式如下方法:

- (IBAction)mybuttontapped:(id)sender; 

您需要在界面生成器連接您的按鈕所需事件的處理程序。適用於我。

0

將您的按鈕連接到視圖控制器中的操作。當用戶點擊按鈕時,它將執行該操作。

0

見下文

UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    myButton.frame = CGRectMake(20, 20, 200, 44); // position in the parent view and set the size of the button 
    [myButton setTitle:@"Click Me!" forState:UIControlStateNormal]; 
    // add targets and actions 
    [myButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside]; 
    // add to a view 
    [superView addSubview:myButton]; 

於是就myButton的所有點擊活動將在buttonClicked方法接收, 代碼實現buttonClicked方法,

-(void) buttonClicked:(id) sender 
{ 
    UIButton* myButton = (UIButton*) sender; 

    ........ 

    ....... 
}