Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.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 多单元';这些按钮似乎是相互关联的_Swift_Uitableview_Uibutton - Fatal编程技术网

Swift 多单元';这些按钮似乎是相互关联的

Swift 多单元';这些按钮似乎是相互关联的,swift,uitableview,uibutton,Swift,Uitableview,Uibutton,我有一个简单的UIButton链接到我的手机上,奇怪的是当我选择它并向下滚动一点时,它似乎也被另一个手机选中了。它们之间的距离是偶数,所以如果我喜欢两个单元格,再往下看,另外两个单元格的按钮也会被选中 我已经包含了按钮的代码,但我的所有其他按钮似乎都不是这样操作的。我可能得编写一本字典,看看这是否有用 @iAction func UpButton(发送方:AnyObject){ 由于单元格在滚动时会被重用,因此您需要在其prepareForReuse中清除单元格中的任何UI状态。此外,您不应该

我有一个简单的UIButton链接到我的手机上,奇怪的是当我选择它并向下滚动一点时,它似乎也被另一个手机选中了。它们之间的距离是偶数,所以如果我喜欢两个单元格,再往下看,另外两个单元格的按钮也会被选中

我已经包含了按钮的代码,但我的所有其他按钮似乎都不是这样操作的。我可能得编写一本字典,看看这是否有用

@iAction func UpButton(发送方:AnyObject){


由于单元格在滚动时会被重用,因此您需要在其prepareForReuse中清除单元格中的任何UI状态。此外,您不应该基于UI状态进行任何计算,而应该依赖于相应模型对象中的状态。一旦单元格在滚动时被重用,您将需要在其prepareForReuse中清除单元格中的任何UI状态此外,您不应该基于UI状态进行任何计算,而应该依赖于相应模型对象中的状态
    var button = sender as! DOFavoriteButton

    if button.selected == true{
        let hitPoint = sender.convertPoint(CGPointZero, toView: self.tableView)
        let hitIndex = self.tableView.indexPathForRowAtPoint(hitPoint)
        let object = objectAtIndexPath(hitIndex)
        object.incrementKey("count", byAmount: -1)
        self.tableView.reloadData()
        object.saveInBackground()
    }
    else
    {
        let hitPoint = sender.convertPoint(CGPointZero, toView: self.tableView)
        let hitIndex = self.tableView.indexPathForRowAtPoint(hitPoint)
        let object = objectAtIndexPath(hitIndex)
        object.incrementKey("count", byAmount: 1)
        self.tableView.reloadData()
        object.saveInBackground()



}