当选择 UITableViewCell 时,防止自定义 AccessoryView 显示选择
要重现此情况,请创建一个 UITableView,其中包含具有自定义 AccessoryView 的单元格(例如用于执行特定操作的按钮,其中触摸 UITableViewCell 的其他部分应执行不同的操作)。
如果您触摸(选择)UITableView,AccessoryView 也会显示选择(就像被触摸一样)。我想防止这种情况发生,并且只在它们实际触摸 AccessoryView 时显示 AccessoryView 的选定状态。
预先感谢,
新郎
To reproduce this, create a UITableView that contains cells with custom AccessoryViews (such as buttons to perform a specific action where touching the other part of the UITableViewCell should perform a different action).
If you touch (select) the UITableView, the AccessoryView shows selection (as thought it was touched) as well. I want to prevent this and only show the AccessoryView's selected state when they actually touch the AccessoryView.
Thanks in advance,
groomsy
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
当 UIButton 设置为 UITableViewCell 的accessoryView时,当选择其超级视图(UITableViewCell)时,将针对accessoryView(本例中为UIButton)调用setHighlighted。
为了解决这个问题,我们需要子类化 UIButton,重写它的 setHighlighted setter 以忽略它的父视图 isSelected 或 isHighlighted。
AccessoryViewUIButton.m
When UIButton is set as the accessoryView of a UITableViewCell, setHighlighted will be called for the accessoryView (the UIButton in this case) when its superview (the UITableViewCell) is selected.
To fix this, we need to subclass UIButton, override its setHighlighted setter to ignore if its superview isSelected or isHighlighted.
AccessoryViewUIButton.m
您是否使用自定义
UITableViewCell
子类?我会尝试这样做并覆盖该类的
setSelected:(BOOL)selected
以确保按照您想要的方式处理事情。Are you using a custom
UITableViewCell
subclass? I would try doing so and overridingsetSelected:(BOOL)selected
for that class to make sure things are handled as you want.点击表格单元格时,附件视图不会发光或显示选择。我认为您希望 tableViewCell 的蓝色选择状态在accessoryViews 背景上不可见。这是正确的吗?
我建议创建您自己的自定义 tableViewCell 并将单元格的选择样式设置为 UITableViewCellSelectionStyleNone 并将 tableRowSelection 处理为单元格侧的 setSelected 状态,而不是附件视图。
或者只是将附件视图的背景设置得大一点,并且不要将其背景颜色设置为clearColor。这样单元格的选择状态也不会显示在accessoryView上。
Accessory View would not glow or show selection when the table cell is tapped. I think you want the tableViewCell's blue color selection state to not be visible on the accessoryViews background. is that correct?
I would suggest creating your own custom tableViewCell and setting the cell's selectionStyle to
UITableViewCellSelectionStyleNone
and handling the tableRowSelection to setSelected state for the cell side alone and not the accessory view.or just make the accessory view's background a little larger and dont set it backgroundColor to clearColor. that way the selection state of the cell wont be shown on the accessoryView as well.
对表格视图单元格进行子类化,并重写以下方法:
并确保按钮的
选定
和突出显示
状态重置为NO< /code> 调用超类方法后。
Subclass the table view cell, and override the following methods:
and make sure the button's
selected
andhighlighted
states are reset toNO
after calling the superclass method.