vitaliy-paliy / Messenger

iOS - Real-time messaging app 🎨
Apache License 2.0
616 stars 87 forks source link

Problem with accept/reject friend request button #19

Closed n9lvc5 closed 3 years ago

n9lvc5 commented 3 years ago

This is the same issue as #18 , But the solution was never posted.

From: FriendRequestCell.Swift

private func setupAcceptButton() {

        acceptButton.translatesAutoresizingMaskIntoConstraints = false
        acceptButton.setTitle("ACCEPT", for: .normal)
        acceptButton.titleLabel?.font = UIFont.boldSystemFont(ofSize: 12)
        let gradient = setupGradientLayer()
        gradient.frame = bounds
        acceptButton.layer.insertSublayer(gradient, at: 0)
        acceptButton.tintColor = .white
        acceptButton.layer.cornerRadius = 12
        acceptButton.layer.masksToBounds = true

        debugPrint("*** Marker 10")
        acceptButton.addTarget(self, action: #selector( addButtonPressed), for: .touchUpInside)
                 debugPrint("*** Marker 11")
        addSubview(acceptButton)
        let constraints = [
            acceptButton.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -16),
            acceptButton.bottomAnchor.constraint(equalTo: centerYAnchor),
            acceptButton.widthAnchor.constraint(equalToConstant: 75),
            acceptButton.heightAnchor.constraint(equalToConstant: 20)
        ]

        NSLayoutConstraint.activate(constraints)
        //addButtonPressed()
    }

accecpt.addTarget is the issue. Nothing happens when touched. The syntax seems to correct. The order seems to be correct as well. I question the location of it, though. Or is it something simple?

Marker 10 and 11 do show up without error.

n9lvc5 commented 3 years ago

Found the problem. Seems like iOS 14.5 has changed some rules.

https://developer.apple.com/forums/thread/661508

adding this line to init(style:reuseIdentifier:) made the button respond to tap.

self.contentView.isUserInteractionEnabled = true

hence:

override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {

        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.contentView.isUserInteractionEnabled = true

I'm going to assume that this will also work on the settings view as well.

arno608rw commented 3 years ago

fix all button in all cell

n9lvc5 commented 3 years ago

@arno608rw , I don't understand your comment. Can you please elaborate.