ios - 禁用所有 UITableViewCells 用户交互

标签 ios swift uitableview

嘿,我有一个 UITableView。有 4 个大单元格(因此它们并没有全部显示在屏幕上)。在应用程序的不同点上,我想为所有这些禁用用户交互,但是当我运行此代码时出现 nil unwrap 错误:

for row in 0...3 {
     let cell = tableView.cellForRowAtIndexPath(NSIndexPath(forRow: row, inSection: 2)) as! AnswerTextChoiceCell
     cell.userInteractionEnabled = reEnable ? true : false
}

我猜这是因为它无法获取单元格,因为它没有显示在屏幕上。我将如何禁用所有单元格的所有用户交互?

I don't want to disable the user interaction on the tableView as it will prevent the user from scrolling.

如有任何建议,我们将不胜感激!

最佳答案

尝试一次。

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        //Configure the cell

        if indexPath.row == yourcell {
           cell.userInteractionEnabled = false
        }
        return cell!
    }

希望这对您有所帮助。

关于ios - 禁用所有 UITableViewCells 用户交互,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39164006/

相关文章:

ios - 为什么 iOS7 中的 bottomLayoutGuide 和 automaticallyAdjustsScrollViewInsets 没有考虑 UIToolBar 的高度(使用自动布局)

swift - 从另一个 TableView 添加行 - Swift

ios - 如何使用适用于 iOS 的 NSCoder、NSObject 和 Swift 3 解码 Double

uitableview - Swift - 检索存储在自定义 tableview-cells 中的信息

objective-c - UItableview 中的选项卡栏

ios - 如何以编程方式创建布局约束

ios - 如何 'pop' 导航 Controller 及其所有 View Controller

ios - 放松到 HomeViewController 的正确方法?不平衡误差

swift - 在快速分配时

ios - 如何在 Swift 的 UITableView 中截取选定行的屏幕截图并将其保存为 UIImage?