iPhone - 从自定义单元格捕获 UIButton 触摸事件
我想构建一个自定义表视图单元格并在其中放入一个按钮,当用户单击该按钮转到方法时,该方法将知道按下了哪个单元格。
谢谢
i would like to build a custom table view cell and put in him a button and when the user click the button to go to a method-and the method will know which cell the button was pressed.
thx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
希望这个工作
Hope this work
您可以给按钮一个标签。如果将此标记设置为单元格的数量indexPath.row,您始终可以通过检索标记值来确定从哪个单元格单击按钮。
顺便说一句,按钮标签必须是整数,但 sow 是indexPath.row。
在这里,我创建了一个自定义单元格,显示“Huis”的详细信息。当为单元格设置对象时,我还传递了我正在填充的单元格的indexPath.row。
然后在自定义单元格中,在设置对象时,我还为按钮设置了标签值,如下所示:
该按钮可能已经创建/初始化,在这种情况下,您只需设置标签。现在,在处理 ControlEvent 的函数中,您可以像这样访问此标记:
You can give the button a tag. If you set this tag to be the number of the cells indexPath.row you can always determine from which cell the button was clicked by retrieving the tag Value.
Button tag has to be an integer btw, but sow is indexPath.row.
Here I create a custom cell displaying details of a 'Huis'. When setting the object for the cell I also pass the indexPath.row of the cell that I am filling.
Then in the custom cell, upon setting the object, I also set the tag value for my button like this:
The button might have already been created / initialized, in that case you only set the tag. Now in the function handling your ControlEvent you can access this tag like so: