Iphone UITableCell按钮触碰内部,带有已单击按钮的单元格索引
我有一个带UITableCells的UITable,如下所示: [我的标签我的按钮] [我的标签我的按钮] [我的标签我的按钮] [我的标签我的按钮] 我希望我的HandlerCellButtonClick也能获得单元格索引的引用。当按下按钮时,我如何获得对该索引的引用Iphone UITableCell按钮触碰内部,带有已单击按钮的单元格索引,iphone,objective-c,Iphone,Objective C,我有一个带UITableCells的UITable,如下所示: [我的标签我的按钮] [我的标签我的按钮] [我的标签我的按钮] [我的标签我的按钮] 我希望我的HandlerCellButtonClick也能获得单元格索引的引用。当按下按钮时,我如何获得对该索引的引用 /**由表调用以获取索引所需的单元格*/ -(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)inde
/**由表调用以获取索引所需的单元格*/
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{
...
//初始单元
...
//配置单元格自定义按钮处理程序
[cell.myButton addTarget:self action:@selector(handlerCellButtonClicked)for controlEvents:UIControlEventTouchUpInside];
返回单元;
}
/**单击单元格中的按钮时的处理程序*/
-(无效)手柄单元格按钮已单击{
NSLog(@“单击单元格myButton”);
}
使用ui按钮标签
属性
-(UITableViewCell*)tableView:(UITableView *) tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//init cell
//configure the cells custom button handlers
cell.myButton.tag = indexPath.row;
[cell.myButton addTarget:self action:@selector(handlerCellButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
return cell;
}
/** handler when the button in the cell is clicked */
- (void)handlerCellButtonClicked:(UIButton *)sender
{
NSLog(@"%d cell myButton is clicked", sender.tag);
}
您如何确定选择器将传递发件人?(handlerCellButtonClicked:)应将发件人传递给目标,对吗?您只能使用addTarget@selector方法将(UIButton*)对象作为参数传递。就这样。“UIControlEventTouchUpInside”事件也会将按钮作为参数发送。希望您理解。@Ramshad:这非常有效,在方法发送UIButton之后添加冒号@selector(handlerCellButtonClicked:),我可以获得标记。我的问题是,如果我删除了行,那么标记是不正确的,因为索引已经更改了。但我可以把这当作另一个问题来发帖。谢谢您的帮助。@Ramshad标签必须是NSInteger还是可以是任何对象?可能是的重复项