我试图忽略添加到我的自定义UITableViewCell子类的某些子视图的触摸。我为该子视图设置了专属触摸为YES,但触摸仍会触发单元格选择。 有没有办法避免该选择只是当触摸是在该子视图? UIView的 像 感谢exclusiveTouch添加到子视图UITableViewCell
1
A
回答
1
以我的经验,@ Ali3n的解决方案不起作用view.userInteractionEnabled = NO )。当您点击视图时,单元格仍处于选中状态。
但是,我发现,如果你添加一个UIButton作为子视图,并添加你的子视图,那么它的确如你所期望的那样工作 - 即你点击按钮覆盖的区域, 未选择。 如果您使用自定义样式的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];
1
你可以在这些意见中禁用用户互为作用使用userInteractionEnabled属性: - (即使用
view.userInteractionEnabled = NO;
相关问题
- 1. 向UITableViewCell添加子视图
- 2. 动态添加子视图到UITableViewCell
- 3. 将子视图添加到UITableViewCell内容视图
- 4. 将子视图添加到UITableViewCell:滚动时添加了几次
- 5. 动态添加子视图的UITableViewCell
- 6. 在UITableViewCell的子视图中添加UIViewController
- 7. 添加子视图的UITableViewCell问题
- 8. 滚动后,删除添加到UITableViewCell的contentView的子视图?
- 9. 添加子视图到静态UITableViewCell不工作
- 10. iOS将动态子视图添加到uitableviewcell中
- 11. 将子视图添加到UITableViewCell以替换单元格选择
- 12. 动态添加边框子视图到UITableViewCell
- 13. 如何将UIGestureRecognizer添加到UITableViewCell子视图?
- 14. iOS - 捕获按钮点击子视图添加到UITableViewCell
- 15. UITableViewCell子视图滚动时添加到错误的单元格
- 16. 在iOS5中将子视图添加到UITableViewCell中
- 17. 删除并添加子视图到自定义UITableViewCell
- 18. WKWebView添加到子视图
- 19. 添加SDNestedTable到子视图
- 20. 添加子视图到UITableCellView
- 21. 添加子视图到UITabBarController
- 22. 如何添加子视图到视图
- 23. UITableViewCell子类 - 在IBAction上添加子视图
- 24. 将exclusiveTouch设置为自定义UITableViewCell
- 25. 添加子视图到主视图在tableViewController添加子视图到表视图,而不是在swift视图
- 26. 如何删除以前的子视图,并添加新的子视图的UITableViewCell
- 27. iOS - 将子视图添加到子视图控制器视图
- 28. 将子视图添加到UINavigationController子类
- 29. 将子视图添加到UICollectionViewCell子类?
- 30. 添加不同视图的UITableViewCell
是的,做到了,但同样的问题。恐怕与后面的表单元格有关。 – 2012-01-18 21:04:19