我使用同一個動作的5個按鈕,想知道哪個按鈕被稱爲我對5個按鈕使用相同的動作,並想知道哪個按鈕被調用?
0
A
回答
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)
{
}
簡單,你可以輕鬆地查找你點擊了哪個按鈕。
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);
}
試試這個,那麼請逆向工程&牛逼我..
相關問題
- 1. 使事件的多個按鈕,並知道被點擊了哪個按鈕
- 2. Android的 - 按鈕偵聽知道哪個按鈕被點擊
- 3. Xamarin Grid如何知道哪個按鈕被按下
- 4. 如何知道哪個按鈕被按下?
- 5. 知道哪個按鈕被按下了! GTK
- 6. 一個按鈕處理2個不同按鈕的相同事件,取決於哪個按鈕被點擊
- 7. 知道按鈕被按住的時間
- 8. JSpinner的哪個按鈕被按下了?
- 9. 如何知道CLLocationManager使用哪個警報按鈕?
- 10. 使按鈕調用相同按鈕的方法
- 11. 在WebView中,如何知道哪個按鈕被點擊?
- 12. 檢測哪個按鈕被按下
- 13. 我可以用什麼來追蹤哪個按鈕被按下?
- 14. 知道在哪個單元格中選擇了哪個按鈕
- 15. GridView中的按鈕:我如何知道哪個項目?
- 16. 按一個按鈕,並有相同的按鈕出現在同一頁
- 17. 用JavaScript查找多個按鈕中按下哪個按鈕
- 18. 識別哪個單選按鈕被檢查並使用php
- 19. 使用jQuery的多個按鈕動作
- 20. 多個活動上的相同按鈕
- 21. ActionListener如何知道按下了哪個按鈕?
- 22. 知道在Javascript中按下哪個按鈕
- 23. 如何知道在Node.js中按下了哪個'Submit'按鈕
- 24. 使用相同的2個控制按鈕控制多個輸入按鈕
- 25. 我怎樣才能知道哪些提交按鈕被點擊
- 26. 哪個按鈕調用javascript文件
- 27. 檢查哪個按鈕被按下gtk3使用python
- 28. 我如何知道哪個按鈕在flex中單擊?
- 29. 5個按鈕訪問相同的啓動腳本
- 30. 多個按鈕調用相同的函數。可以找出哪個按鈕稱爲函數?
allbtn是的UIButton * allbtn; – Vishal 2013-02-12 06:25:11