我有以下过程。每个 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/