如何使表格视图单元格上的按钮调用正确的 tableView:cellForRowAtIndexPath? [英] How to make a button on a table view cell call the correct tableView:cellForRowAtIndexPath?

查看:20
本文介绍了如何使表格视图单元格上的按钮调用正确的 tableView:cellForRowAtIndexPath?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个按钮,它是自定义 UITableViewCell 的一部分.我想要的是当有人单击按钮时,为该单元格调用正确的 tableView:cellForRowAtIndexPath.

I have a button that is part of a custom UITableViewCell. What I want is that when someone clicks the button, that the proper tableView:cellForRowAtIndexPath to be called for that cell.

如何将按钮绑定到正确的 cellForRowAtIndexPath?

How do I tie the button to the proper cellForRowAtIndexPath?

任何建议和/或代码示例将不胜感激

Any suggestions and / or code samples will be highly appreciated

推荐答案

您可以从触摸事件中获取 indexPath.将您的 buttonTapped 方法修改为:

You can get the indexPath from the touch event. Modify your buttonTapped method to be this:

- (void) buttonTapped:(id) sender forEvent:(UIEvent *)event

然后使用类似以下内容:

and then use something like the following:

NSIndexPath *indexPath = [tableView indexPathForRowAtPoint:[[[event touchesForView:sender] anyObject] locationInView:tableView]];

这篇关于如何使表格视图单元格上的按钮调用正确的 tableView:cellForRowAtIndexPath?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆