I have a button that when clicked turns into a checkmark. It works on all simulators including X and XR but not on an actual X or XR device (according to friends using TestFlight). It works on several other devices though. Wondering if there's anything to do with X and XR specifically or may be constraints, clips to bounds? The problem is it isn't showing the checkmark or adding the value associated with its cell to an array I have, so I don't think it's selectable on those phones.
let button: UIButton = {
let button = UIButton()
button.translatesAutoresizingMaskIntoConstraints = false
button.layer.masksToBounds = true
button.isUserInteractionEnabled = true
button.clipsToBounds = true
button.contentMode = .scaleAspectFit
return button
}()
Constraints
button.topAnchor.constraint(equalTo: self.topAnchor).isActive = true
button.centerYAnchor.constraint(equalTo: self.centerYAnchor).isActive = true
button.rightAnchor.constraint(equalTo: self.rightAnchor, constant: -(width/40)).isActive = true
button.widthAnchor.constraint(equalToConstant: width/8).isActive = true
Gesture Recognizer
private func setupGestureRecognizer() {
let joinButtonTapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(joinButtonTapped))
button.addGestureRecognizer(joinButtonTapGestureRecognizer)
}
@objc private func joinButtonTapped() {
delegate?.joinButtonTapped(inCell: self, button: button)
}
JoinButtonTapped -> Plus Button to Checkmark and adds group name to array
extension SearchGroupsVC: GroupsViewCellDelegate {
func joinButtonTapped(inCell cell: UITableViewCell, button: UIButton) {
guard let indexPath = tableView.indexPath(for: cell) else { return }
if searchBar.text?.count != 0 {
group = filteredTypes[indexPath.row]
} else {
group = allGroups[indexPath.row]
}
if selected.contains(group) {
if self.traitCollection.userInterfaceStyle == .dark {
button.setImage(UIImage(named: "plus_white"), for: .normal)
} else {
button.setImage(UIImage(named: "plus_black"), for: .normal)
}
selected.remove(at: selected.index(of: group)!)
} else if !selected.contains(group){
if self.traitCollection.userInterfaceStyle == .dark {
button.setImage(UIImage(named: "checkmark_white"), for: .normal)
} else {
button.setImage(UIImage(named: "checkmark_black"), for: .normal)
}
selected.append(group)
}
}
}