ios - 无法在 UITableViewCell 中禁用 UIButton

标签 ios swift uitableview uibutton

我在禁用 UITableViewCell 中的 UIButton 时遇到问题。代码如下:

func disableAddAudio(reEnable: Bool = false) {

        headerView.recordButton.userInteractionEnabled = reEnable ? true : false
        for index in 0...audioViewModelArray.count - 1 {
            let cell = tableView.dequeueReusableCellWithIdentifier("AddedAudioTableCellReuseIdentifier", forIndexPath: NSIndexPath(forRow: index, inSection: 0)) as! AddedAudioTableCell
            cell.trashButton.userInteractionEnabled = false
        }
    }

在这里,如果我禁用 UITableView header View 中的按钮,则没有问题。然而,即使我将其设置为 false,按钮 trashButton 似乎也没有禁用。知道我在这里可能做错了什么吗?

最佳答案

这样试试

let cell = tableView.cellForRowAtIndexPath(NSIndexPath(forRow: index, inSection: 0)) as! AddedAudioTableCell
cell.trashButton.userInteractionEnabled = false

关于ios - 无法在 UITableViewCell 中禁用 UIButton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38844798/

相关文章:

ios - 标签栏项目的 UIColor 未选中和更改标签栏颜色

ios - 无法按预期显示幻灯片菜单下方的状态栏

ios - Base64 字符串解码后,Swift 无法识别/n 换行符

带有右导航箭头的 iOS 联系人样式按钮

ios - 如何在 iOS Swift4 中滚动时增加/减小 UILabel 字体大小以及宽度和高度

ios - UITableView 部分标题未显示

ios - registerDefaults 未反射(reflect)在设置应用程序中

objective-c - 为什么我无法从自定义 UIView 类中拖动导出?

swift - Swift 中的 NSMenu 选择器

iphone - 尝试调整 UITableView 的大小会导致屏幕出现一秒钟的故障,然后才能正确显示