防止自定义辅助视图在选择uitaiteViewCell时显示选择
-
12-10-2019 - |
题
为了重现此功能,创建一个包含具有自定义配件视图的单元格(例如,按钮执行特定动作,触摸UitableViewCell的另一部分应执行不同的动作)。
如果您触摸(选择)uitableview,则配件视图也显示选择(如认为它被触摸)。我想防止这一点,并且仅在访问辅助视图时才显示附件的所选状态。
提前致谢,
饰面
解决方案
您正在使用自定义吗 UITableViewCell
子类?我会尝试这样做和覆盖setSelected:(BOOL)selected
为了使该课程确保按照需要处理事情。
其他提示
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.
为了解决这个问题,我们需要对Uibutton进行亚级,覆盖其sethighlight的设置器,以忽略其超级浏览器是否已发出或iShighlight。
附件Viewuibutton.m
#import "AccessoryViewUIButton.h"
@implementation AccessoryViewUIButton
// Subclass only works for buttonWithType:custom
- (id)initWithFrame:(CGRect)aRect
{
// Call the superclass's designated initializer
self = [super initWithFrame:aRect];
return self;
}
- (void)setHighlighted:(BOOL)isHighlighted {
/* Overridden to do nothing if superview is selected or highlighted */
UITableViewCell* theCell = (UITableViewCell*) self.superview;
if ([self.superview isKindOfClass:[UITableViewCell class]]) {
if ([theCell isSelected] || [theCell isHighlighted])
return;
}
[super setHighlighted:isHighlighted];
}
- (void)dealloc {
[super dealloc];
}
@end
当表单元点敲击时,附件视图不会发光或显示选择。我认为您希望TableViewCell的蓝色选择状态在附件背景上不可见。那是对的吗?
我建议您创建自己的自定义tableviewcell,并将单元格的选择风格设置为 UITableViewCellSelectionStyleNone
并单独将tableRowselection处理到单独的单元侧而不是附件视图的设置状态。
或者只是使附件视图的背景更大一点,然后不要将其设置为ClearColor的背景色。这样,单元格的选择状态也不会在附件上显示。
子类查看单元格,并覆盖以下方法:
- (void) setHighlighted: (BOOL) highlighted;
- (void) setHighlighted: (BOOL) highlighted
animated: (BOOL) animated;
- (void) setSelected: (BOOL) selected;
- (void) setSelected: (BOOL) selected
animated: (BOOL) animated;
并确保按钮的 selected
和 highlighted
状态被重置为 NO
调用超类方法后。