Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 在自定义tableview单元格中触摸开始取消didselectrowatindexpath函数_Swift_Uitableview_Didselectrowatindexpath_Touchesbegan - Fatal编程技术网

Swift 在自定义tableview单元格中触摸开始取消didselectrowatindexpath函数

Swift 在自定义tableview单元格中触摸开始取消didselectrowatindexpath函数,swift,uitableview,didselectrowatindexpath,touchesbegan,Swift,Uitableview,Didselectrowatindexpath,Touchesbegan,我有自定义单元格的tableview。在自定义单元格中,我有一个视图,它是自定义UIView类。在这个自定义UIView类中,我重写了touchesBegind和touchesEnded方法,以在按下视图时更改自定义视图的背景色。在tableview中,单元格touchesBegind和touchesEnded方法非常有效。当我按下tableview单元格时,视图的背景正在更改。但在这种情况下,tableView的didselectrowat函数不起作用。此自定义UiView类取消didSele

我有自定义单元格的tableview。在自定义单元格中,我有一个视图,它是自定义UIView类。在这个自定义UIView类中,我重写了touchesBegind和touchesEnded方法,以在按下视图时更改自定义视图的背景色。在tableview中,单元格touchesBegind和touchesEnded方法非常有效。当我按下tableview单元格时,视图的背景正在更改。但在这种情况下,tableView的didselectrowat函数不起作用。此自定义UiView类取消didSelectRowat函数。这个问题有什么解决办法吗

自定义类如下所示:

类BildirisItemBackground:UIView{

override init(frame: CGRect) {
    super.init(frame: frame)

}

required init?(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)

}

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    self.backgroundColor = UIColor(red: 216/255, green: 216/255, blue: 216/255, alpha: 0.3)
}

override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
    DispatchQueue.main.asyncAfter(deadline: .now() + 0.05, execute: {
        ( self.backgroundColor = UIColor(red: 216/255, green: 216/255, blue: 216/255, alpha: 0.0))
    })
}
override init(帧:CGRect){
super.init(frame:frame)
}
必需的初始化?(编码器aDecoder:NSCoder){
super.init(编码者:aDecoder)
}
覆盖func TouchesBegind(Touchs:Set,带有事件:UIEvent?){
self.backgroundColor=UIColor(红色:216/255,绿色:216/255,蓝色:216/255,alpha:0.3)
}
覆盖函数touchesend(touchs:Set,带有事件:UIEvent?){
DispatchQueue.main.asyncAfter(截止日期:.now()+0.05,执行:{
(self.backgroundColor=UIColor(红色:216/255,绿色:216/255,蓝色:216/255,alpha:0.0))
})
}
}

和didSelectrowat函数:

func tableView(tableView:UITableView,didSelectRowAt indexPath:indexPath){ 打印(indexPath.row) }


我希望打印选定的tableView行。但是没有打印任何内容。

在touchStart()方法中使用super方法。当一个类从另一个类继承时,继承的类称为子类,它继承的类称为其超类。这里的超级类是
UIView
。添加
super.OverrideMethodName()
后,它将覆盖
UIView
touchStart()

override func touchsbegind(touch:Set,带有事件:UIEvent?){
self.backgroundColor=UIColor(红色:216/255,绿色:216/255,蓝色:216/255,alpha:0.3)
super.touchesbeated(touches,with:event)
}

尝试调用super方法。超级的。触摸开始(……)非常感谢,它正在工作。
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    self.backgroundColor = UIColor(red: 216/255, green: 216/255, blue: 216/255,alpha: 0.3)
    super.touchesBegan(touches, with: event)
}