2013-02-12 41 views

回答

0
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); 
button.tag=1; 
[view addSubview:button]; 

-(void)aMethod:(id)sender{ 

UIButton *button = (UIButton *)sender; 

int clickedBtnTag = button.tag ; 

Nslog("clicked button tag is %d",clickedBtnTag); 

} 

試試這個,那麼請回復我..

2

給標籤值的按鈕,在筆尖然後在您的按鈕操作補充一點:現在

allbtn = sender; 
    btntag = allbtn.tag; 
    NSLog(@"btntag:%d",btntag); 
    if(btntag==1) 
    { 
    } 

簡單,你可以輕鬆地查找你點擊了哪個按鈕。

+0

allbtn是的UIButton * allbtn; – Vishal 2013-02-12 06:25:11

4

在這種情況下,請嘗試爲按鈕分配唯一標籤。

在目標方法恢復按鈕標籤如下

-(void)targetMethod:(id)sender{ 

UIButton *button = (UIButton *)sender; 

int clickedButtonTag = button.tag ; 


} 
+0

謝謝你的幫助...... – 2013-02-12 06:26:52

0

使用:

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); 
button.tag=1; 
[view addSubview:button]; 

然後使用:

-(void)aMethod:(id)sender{ 

UIButton *button = (UIButton *)sender; 

int clickedBtnTag = button.tag ; 

Nslog("clicked button tag is %d",clickedBtnTag); 

} 

試試這個,那麼請逆向工程&牛逼我..

相關問題