Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Buttons and some user interactions are not responding with iOS14 app

I am struggling with a strange bug with my iOS app. When using a simulator with iOS 13 application works as it should, but when using iOS 14 buttons, switches, and other functionalities are not responding. There is no error output in the console. I don't understand why this happens only with XCode 11 and iOS 14.

This a snippet with initializing one of my buttons in the View.

 let logButton: UIButton = {
    let button = UIButton()
    button.translatesAutoresizingMaskIntoConstraints = false
    button.setLogInButton()
    button.setTitle(NSLocalizedString("log_in", comment: ""), for: .normal)
    return button
}()

Here I'm assigning the target to the button.

   override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        initConstraints()
        backgroundColor = UIColor().settingsTableViewCellColor()
        logButton.addTarget(self, action: #selector(buttonLogInLogOut), for: .touchUpInside)
    }

There is the action

@objc func buttonLogInLogOut(_ sender: UIButton){
    print("Log in clicked")
    delegate?.logInLogOutFunc(sender)
}

As I said the buttons (switches, and others) are not responding ONLY in iOS 14. It looks like targetActions are not working.

Thanks for any kind of help. Regards Matt

like image 704
Matt199 Avatar asked Dec 07 '22 10:12

Matt199


1 Answers

I had the same problem with a button in a table cell not working

For some reason you have to add the button to the contentView of the cell instead of the cell itself as follows

cell.contentView.addSubView(button)

Worked for me afterwards

like image 120
Tony C Hansord Avatar answered Dec 09 '22 22:12

Tony C Hansord