我做了一个自定义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