我做了一個自定義cell.In每個自定義單元格有許多按鈕像3〜4我要加點觸手勢爲cell.So,我可以唯一地標識哪個小區的按鈕中的每個按鈕被clicked.I尋覓了很多但沒有找到任何好的解決方案。如何在iOS中的UItableCell中的按鈕上添加點按手勢?
請告訴我。
我做了一個自定義cell.In每個自定義單元格有許多按鈕像3〜4我要加點觸手勢爲cell.So,我可以唯一地標識哪個小區的按鈕中的每個按鈕被clicked.I尋覓了很多但沒有找到任何好的解決方案。如何在iOS中的UItableCell中的按鈕上添加點按手勢?
請告訴我。
您要訪問您可以直接訪問button
,無需手勢的
不喜歡
[yourButton1 addTarget:self action:@selector(selectButtonPressed1:) forControlEvents:UIControlEventTouchUpInside];
yourButton1.tag=indexPath.row;
[yourButton2 addTarget:self action:@selector(selectButtonPressed2:) forControlEvents:UIControlEventTouchUpInside];
yourButton2.tag=indexPath.row;
[yourButton3 addTarget:self action:@selector(selectButtonPressed3:) forControlEvents:UIControlEventTouchUpInside];
yourButton3.tag=indexPath.row;
[yourButton4 addTarget:self action:@selector(selectButtonPressed4:) forControlEvents:UIControlEventTouchUpInside];
yourButton4.tag=indexPath.row;
方法 - 1
-(void)selectButtonPressed1:(UIButton*)sender
{
NSLog(@"selcted button1");
}
方法 - 2
-(void)selectButtonPressed2:(UIButton*)sender
{
NSLog(@"selcted button2");
}
方法 - 3
-(void)selectButtonPressed3:(UIButton*)sender
{
NSLog(@"selcted button3");
}
方法 - 4
-(void)selectButtonPressed4:(UIButton*)sender
{
NSLog(@"selcted button4");
}
我如何識別哪個單元格按鈕被點擊 – Techiee
它是標識的意思是指** yourButton4.tag = indexPath.row; **,它是識別您在tableview上點擊了哪個單元格 –
@deepak - 對此 –
比方說你有按鈕的n個。你有一個butotn動作方法:
你需要連接這個方法到你所有的n個按鈕(觸摸裏面),這樣每當你按下一個按鈕,這個方法就會被擊中。
您可以給標籤值的按鈕,或者您也可以通過thier標題
-(IBAction) nButtonActions:(id)sender{
if([[sender titleLabel] isEqualtoString:@"your button-1 title"]){
//call your method for button -1
}
//or you can do the same using sender.tag
}
使用復原標識識別它們。
button.restorationIdentifier = @"Cell Number _ button tag";
例如
button.restorationIdentifier = [NSString stringWithFormat:@"%@", indexPath.row];
NSString* rowIndexStr = ((UIButton*)sender).restorationIdentifier;
你不需要爲龍頭的姿態。你需要的是一個按鈕動作方法,它可以通過標記或標題 –
來識別動作事件,但是對於不同的單元格,我有很多按鈕,我怎樣才能識別哪個按鈕被按下? – Techiee