gpt4 book ai didi

ios - subview 中的 exclusiveTouch 添加到 UITableViewCell

转载 作者:行者123 更新时间:2023-11-29 11:17:14 24 4
gpt4 key购买 nike

我试图忽略添加到我的自定义 UITableViewCell 子类的某些 subview 的触摸。我将该 subview 的 exclusiveTouch 设置为 YES,但触摸仍会触发单元格选择。有没有办法在那个 subview 中有触摸时避免选择?谢谢

最佳答案

根据我的经验,@Ali3n 的解决方案不起作用(即使用 view.userInteractionEnabled = NO)。当您点击 View 时,该单元格仍处于选中状态。

但是,我发现如果您添加一个 UIButton 作为 subview ,并将您的 subview 添加到它,那么它确实会按您预期的方式工作 - 即您点击按钮覆盖的区域并且单元格是 < em>未被选中。如果您使用自定义样式的 UIButton,那么它看起来与普通 UIView 没有任何不同。

下面是我如何将一个 UISwitch 添加到 accessoryView,它后面有一个不可点击的 UIButton。如果您错过了按钮并点击了背景,则单元格被选中。

UIButton* button =[UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0, 0, 100, 67);
self.accessoryView = button;
self.accessoryView.backgroundColor = [UIColor grayColor];
UISwitch* statusSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(0, 20, 80, 40)];
[self.accessoryView addSubview:statusSwitch];

关于ios - subview 中的 exclusiveTouch 添加到 UITableViewCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8913984/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com