Ios 在tableview中滑动手势
我想在手机上添加滑动手势。它工作正常。但问题是当我刷第一个单元格时,我的第五个单元格也会刷。我知道这个问题。请帮帮我,但我被困了几个小时 让swipeLeft=UISwipeGestureRecognitzerTarget:self,action:selectorself.handleLeftSwipe swipelft.direction=uiswipgesturerecognizerdirection.left table.AddGestureRecognitizerSwipeleftIos 在tableview中滑动手势,ios,iphone,swift,Ios,Iphone,Swift,我想在手机上添加滑动手势。它工作正常。但问题是当我刷第一个单元格时,我的第五个单元格也会刷。我知道这个问题。请帮帮我,但我被困了几个小时 让swipeLeft=UISwipeGestureRecognitzerTarget:self,action:selectorself.handleLeftSwipe swipelft.direction=uiswipgesturerecognizerdirection.left table.AddGestureRecognitizerSwipeleft le
let swipeLeftd = UISwipeGestureRecognizer(target: self, action: #selector(self.handleLeftSwipes))
swipeLeftd.direction = UISwipeGestureRecognizerDirection.right
table.addGestureRecognizer(swipeLeftd)
@objc func handleLeftSwipe(sender: UITapGestureRecognizer) {
print("rigt called")
let location = sender.location(in: self.table)
let indexPath = self.table.indexPathForRow(at: location)
let cell = self.table.cellForRow(at: indexPath!) as! TableViewCell
print("swipe")
cell.myView.frame.origin.x = -94
}
@objc func handleLeftSwipes(sender: UITapGestureRecognizer) {
print("labelSwipedLeft called")
let location = sender.location(in: self.table)
let indexPath = self.table.indexPathForRow(at: location)
let cell = self.table.cellForRow(at: indexPath!) as! TableViewCell
print("swipe")
cell.myView.frame.origin.x = 80
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let identifier = "TableViewCell"
var cell: TableViewCell! = tableView.dequeueReusableCell(withIdentifier: identifier) as? TableViewCell
if cell == nil {
var nib : Array = Bundle.main.loadNibNamed("TableViewCell",owner: self,options: nil)!
cell = nib[2] as? TableViewCell
}
return cell!
}
原因是重复使用你的细胞。我想你在准备之前没有设置任何内容。所以,您的问题在cell.myView.frame.origin.x=80行,对吗?只需在prepareForReuse或cellForRowAt indexPath中将其设置为默认值。您可以显示您的cellforindex吗?@vinbhai4u请选中try tableView.dequeueReusableCellwithIdentifier:,因为:在CellForRowatindexpath中,我必须在左扫时设置两个不同的帧,右扫时设置另一个帧。我会把一切都安排好吗two@varun是的,只需设置单元格默认视图所需的全部内容,因为当您为一个特定单元格设置默认视图时,在滚动过程中,该单元格将被重新使用,并且它的子视图的帧将像以前一样移动。如果我理解正确,则不希望它们保存其帧原点。因此,如上所述,在prepareforuse中设置默认视图