I am experiencing this same issue as well. In addition to the workaround by using iOS 13 simulators, It does seem that running app on a physical device does work; however, that is not a viable solution.
Post
Replies
Boosts
Views
Activity
This thread is exceptionally difficult to follow, but I will echo that I believe I am seeing the same issue in our app. There are numerous instances throughout our app where we have UITableViewCell subclasses that embed buttons within their contentView AND also allow selection such that didSelectRow... will get triggered when the larger cell content is tapped.
As has been described by other posters, the way these buttons/cells are set up has not changed since we began compiling against Xcode 12, but it does seem that their underlying behavior has. Previously, the button taps would be accepted as expected; however, now, the button taps are ignored and the tap goes through to the cell itself.
Here's what I have determined so far: As suggested by other posters, this is in some way tied to contentView.isUserInteractionEnabled. According to the documentation for that property, it is still supposed to default to true.
This issue can be worked around by simply accessing contentView.isUserInteractionEnabled - like by calling: print("\(contentView.isUserInteractionEnabled)")
The workaround will only work when the access is done outside of the initializer. I have tried numerous orderings and combinations, and it seems that if I directly access this property from within the code block of the initializer, it has no effect. However, if the access is made within a function called by the initializer, it does work.
A sample is attached below to further demonstrate the issue and my workaround:
protocol MyCellDelegate: class {
func didTapButtonInCell(_ cell: MyTableViewCell)
}
class MyTableViewCell: UITableViewCell {
weak var delegate: MyCellDelegate?
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
				// Adding either of these calls here does NOT work:
// contentView.isUserInteractionEnabled = true
// print("\(contentView.isUserInteractionEnabled)")
setupMyButton()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private func setupMyButton() {
			 // Adding either of these calls here DOES work:
// contentView.isUserInteractionEnabled = true
// print("\(contentView.isUserInteractionEnabled)")
	
let button: UIButton = {
$0.setTitle("Tap me!", for: .normal)
return $0
}(UIButton(type: .system))
button.addTarget(self, action: #selector(didTapButton(_:)), for: .touchUpInside)
// Add the button to the `contentView` and lay it out accordingly...
}
@objc private func didTapButton(_ sender: UIButton) {
delegate?.didTapButtonInCell(self)
}
}