获取自定义单元格上的节号和行号按钮单击? [英] get section number and row number on custom cells button click?
本文介绍了获取自定义单元格上的节号和行号按钮单击?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有tableview与自定义cell.the表分为许多部分和rows.i有单元格上的自定义按钮。现在我想获得节号和行号,当我点击那个按钮。
关于这个的任何想法
i have tableview with custom cell.the table is divided in many section and rows.i have a custom button on cell. now i want to get section number and row number when i click on that button.? any idea regarding this
推荐答案
您需要在您的视图控制器上实现一个UIControl事件处理方法,并将其设置为全部按钮的处理程序。即在 -tableView:cellForRowAtIndexPath:
函数中,您将执行以下操作:
You'll need to implement a UIControl event-handling method on your view controller, and set that as the handler for all your buttons. i.e. inside your -tableView:cellForRowAtIndexPath:
function you would do something like:
[theCell.button addTarget: self
action: @selector(buttonPressed:withEvent:)
forControlEvents: UIControlEventTouchUpInside];
然后您的事件处理程序将如下所示:
Then your event handler would look like this:
- (void) buttonPressed: (id) sender withEvent: (UIEvent *) event
{
UITouch * touch = [[event touches] anyObject];
CGPoint location = [touch locationInView: self.tableView];
NSIndexPath * indexPath = [self.tableView indexPathForRowAtPoint: location];
/* indexPath contains the index of the row containing the button */
/* do whatever it is you need to do with the row data now */
}
这篇关于获取自定义单元格上的节号和行号按钮单击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文