UISwitch-iOS 14-Swift: Programmatically added Switch doesn't work anymore

Hi there,
I´ve added a SwitchControl to a "SettingsCell". Since I've updated to iOS 14, the Switch is shown in the Settings but I can't switch it anymore. No action is possible.

Code Block
import Foundation
import UIKit
class SettingsCell: UITableViewCell {
// MARK: - Properties
var sectionType: sectionType? {
didSet{
guard let sectionType = sectionType else { return }
textLabel?.text = sectionType.description
SwitchControl.isHidden = !sectionType.constrainsSwitch
}
}
lazy var SwitchControl: UISwitch = {
let SwitchControl = UISwitch()
SwitchControl.isOn = true
SwitchControl.isEnabled = true
SwitchControl.onTintColor = UIColor(red: 55/255, green: 120/255, blue: 250/255, alpha: 1)
SwitchControl.translatesAutoresizingMaskIntoConstraints = false
SwitchControl.addTarget(self, action: #selector(handleSwitchAction), for: .valueChanged)
return SwitchControl
}()
// MARK: - Init
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
addSubview(SwitchControl)
SwitchControl.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true
SwitchControl.rightAnchor.constraint(equalTo: rightAnchor, constant: -12).isActive = true
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
// Mark - selectors
@objc func handleSwitchAction(sender: UISwitch){
if sender.isOn {
print("Turned on")
UIApplication.shared.registerForRemoteNotifications()
}
else{
UIApplication.shared.unregisterForRemoteNotifications()
print("Turned off")
}
}
}

Do someone know a solution for this issue?

Answered by k116082 in 634608022
Hi LuminiCode,
Set cell.contentView.isUserInteractionEnabled to false and you can resolve this issue.
Accepted Answer
Hi LuminiCode,
Set cell.contentView.isUserInteractionEnabled to false and you can resolve this issue.
@k116082,
Thank you so much. I probably spent an hour looking around to see how to fix this for iOS 14.
Such a simple fix!
Hey LuminiCode,

Where did you add that contenView line? In the cellForRow function?
Hey andrew_holmes37,

yep.

Code Block
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCell(withIdentifier: reuseIdentifier, for: indexPath) as! SettingsCell
cell.textLabel?.text = social?.description
cell.imageView?.image = UIImage(systemName: social!.image)
cell.imageView?.tintColor = .systemBlue
cell.contentView.isUserInteractionEnabled = false
return cell
}

hi i have same problem , can someone help ? everything was working fine till ios 14. now switches wont work. i can share files if someone is willing to help ?

can someone help ? 

You should better start your own thread. Not many readers make attention to the thread marked as SOLVED.
UISwitch-iOS 14-Swift: Programmatically added Switch doesn't work anymore
 
 
Q