Kex Kex - 3 months ago 11
Swift Question

Can't disable UIButton in UITableViewCell

I'm having trouble disabling a UIButton in my UITableViewCell. Code is as follows:

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
}
}


here if I disable a button in the UITableView header view there are no issues. However the button
trashButton
does not seem to disable even when I set it to false. Any ideas what I might be doing wrong here?

Answer

try like this

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