如果一个 UITableViewCell 有多个按钮,处理触摸事件的最佳位置在哪里 [英] If a UITableViewCell has multiple buttons, where is the best place to handle touch events
问题描述
我正在以具有多列的表格格式呈现大量数据.几乎每一列都有一个按钮(总共最多 4 个),每一行都是一个 UITableViewCell
.
我怎样才能检测到按钮被触摸了,我应该在哪里处理按钮的触摸事件?我敢肯定,它不应该是 didSelectRowAtIndexPath
方法.
只要我能检测到按下了哪个按钮,我就会获取该特定行中的数据并对其进行操作.因此,我需要知道该行的 indexPath
,以及按下了哪个按钮.
笼统的未详细回答:
- 创建 UITableviewcell 子类,将单元格 ui 元素链接到此类.
- 添加方法 configureWithModel:(Model*)model;//模型是您希望单元格表示的信息
- 操纵该信息或
- 如果您需要操作屏幕或其他对象.创建单元格时,您需要为表格视图单元格子类提供对其他对象的引用.(在代码、故事板或笔尖中).
如何处理 ios 7 中的按钮按下:UITableViewCell 中的按钮不是在 ios 7 下响应(将表格单元格选择设置为无)
如何链接按钮:http://oleb.net/blog/2011/06/creating-outlets-and-actions-via-drag-and-drop-in-xcode-4/>
I'm presenting a lot of data in format of a table with multiple columns. Almost each column has a button (up to 4 in total) and each row is a UITableViewCell
.
How could I detect that the buttons were touched and where should I handle touch events of the buttons? I'm certain, it shouldn't be a didSelectRowAtIndexPath
method though.
As soon as, I could detect which button was pressed, I would fetch the data in that particular row and manipulate it. So, I need to know the indexPath
of the row, as well as what button was pressed on it.
Generalized undetailed answer:
- Create UITableviewcell subclass, link cell ui elements to this class.
- Add method configureWithModel:(Model*)model; //Model being the information you want the cell to represent
- Manipulate that information or
- If you need to manipulate the screen or other objects. You need to give the table view cell subclass a reference to the other objects when the cell is created. (in code or in storyboard or in nib).
how to handle button presses in ios 7: Button in UITableViewCell not responding under ios 7 (set table cell selection to none)
how to link a button: http://oleb.net/blog/2011/06/creating-outlets-and-actions-via-drag-and-drop-in-xcode-4/
这篇关于如果一个 UITableViewCell 有多个按钮,处理触摸事件的最佳位置在哪里的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!