swift - 禁用特定表格 View 单元格的按钮功能

标签 swift uitableview invalidation

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

相关文章:

ios - 重新加载 cellForRowAtIndexPath 时出现问题 - Objective C

Android:如何让自定义 View 部分重绘?

ios - 如何获得 Xcode 项目文件的较短路径

ios - 如何在按钮操作中的 TableViewController 中重新加载 tableview?

ios - NSNotificationCenter - 观察者选择器被调用两次

iphone - 通过 SSCollectionView 重用单元格混淆

iphone - iPhone SDK:从SQLite加载UITableView

swift - 我想在我的开关盒中运行这两个功能,但只运行一个;我该如何解决?

Android invalidate(Rect) 使整个区域无效

c++ - 使用索引避免迭代器失效,保持干净的界面