iOS 13 beta UITableViewCell子视图触摸选择表格视图单元格
因此,我有一个带有自定义iOS 13 beta UITableViewCell子视图触摸选择表格视图单元格,ios,xcode,uitableview,uiview,uitouch,Ios,Xcode,Uitableview,Uiview,Uitouch,因此,我有一个带有自定义UITableViewCell的UITableView,它有自己的自定义子视图 在iOS 12中,可以触摸上面的自定义子视图,它不会选择整个表视图单元格 在iOS 13 Beta版中,触摸自定义子视图也会高亮显示/选择整个表格视图单元格。 final class myTableView: UITableViewController { ....... override final func tableView(_ tableView:
UITableViewCell
的UITableView,它有自己的自定义子视图
在iOS 12中,可以触摸上面的自定义子视图,它不会选择整个表视图单元格
在iOS 13 Beta版中,触摸自定义子视图也会高亮显示/选择整个表格视图单元格。
final class myTableView: UITableViewController {
.......
override final func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
{
//Do things for table view cell selection
}
.......
}
final class CustomChildView : UIView {
........
override final func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?)
{
super.touchesBegan(touches, with: event)
//Do touch down things
}
........
}
final类myTableView:UITableViewController{
.......
重写最终func tableView(tableView:UITableView,didSelectRowAt indexPath:indexPath)
{
//执行表格视图单元格选择操作
}
.......
}
最后一个类CustomChildView:UIView{
........
覆盖最终功能触摸开始(touchs:Set,带有事件:UIEvent?)
{
super.touchesbeated(touches,with:event)
//不要触地
}
........
}
当触摸自定义子对象时,是否有方法取消表格视图单元格选择?您的问题是视图也会自动将选择传递给父对象。
您需要做的是覆盖子自定义视图的setSelected
功能,这样它就不会将选择传播到UI
树的上部节点
override func setSelected(selected: Bool, animated: Bool) {
// Add here code to not select parent
}
在Reinder中,您有6种不同的方法(其中一些是众所周知的设计模式)在视图控制器之间传递数据,包括使用属性,segues
和NSNotificationCenter
最终类CustomChildView:ui按钮{
........
覆盖最终功能触摸开始(touchs:Set,带有事件:UIEvent?)
{
super.touchesbeated(touches,with:event)
//不要触地
}
........
}
将UIView更改为UIButton,现在它可以正常工作。是否可以从子类“子自定义视图”引用父表视图?@Gizmodo请检查:我将自定义子视图从UIView更改为UIButton。现在它按预期工作。我猜UIButton不知何故阻止了触碰在树上的进展。
final class CustomChildView : UIButton {
........
override final func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?)
{
super.touchesBegan(touches, with: event)
//Do touch down things
}
........
}