我有以下过程。每个tableview单元都有一个作为标签引用的objectId。当用户按下该单元格中的“喜欢”或“不喜欢”按钮时,该单元格中的objectId将保存到PFUser的currentUserObjectIdsTouched(“ array”)中。当特定用户已经基于他们的currentUserObjectIdsTouched已经喜欢或不喜欢该单元格时,我想禁用该特定单元格的喜欢和不喜欢功能。我已经做好一切,直到失去能力。如何禁用两个按钮。

我在cellForRow中的按钮语法是... cell.likesButton()

     cellForRow:

        if currentUserObjectIdsTouched.contains(cell.objectId.text!) {
            print("should invalidate buttons for cell with objectId \(cell.objectId.text!)")
        }

最佳答案

您需要在cellForRowAt内部执行此操作

cell.likesButton.isEnabled = !(currentUserObjectIdsTouched.contains(cell.objectId.text!))


像这样直接从模型中进行比较是个好习惯

let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! CustomCell
let item = arr[indexPath.row]
cell.likesButton.isEnabled = !(currentUserObjectIdsTouched.contains(item.objectId))

关于swift - 禁用特定表 View 单元的按钮功能,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58616487/

10-16 12:31