not work UIButton from UICollectionViewCell
Try this :
Solution 1
In ViewController
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reviewAverageRateCellid, for: indexPath) as! ReviewAverageRate
cell.detailControllr = self
cell.giveReviewBtn.addTarget(self, action: #selector(self.giveReviewBtnTarget), for: .touchUpInside)
return cell
}
func giveReviewBtnTarget() {
// add your code
}
Solution 2
In cell class
btn.addTarget(self, action: #selector(self.giveReviewBtnTarget), for: .touchUpInside)
Button inside CollectionView not clickable
After searching the entire web pretty much, I finally found the solution that was in the comment of this SO answer: https://stackoverflow.com/a/44908916/406322
I needed to add this in MyCollectionViewCell:
self.contentView.isUserInteractionEnabled = false
I think the cell selection was hijacking the touch event.
UIButton does not function in collectionView cell
I believe, to get your button action / target to register correctly, you need to declare them as lazy:
lazy var flipToBack: UIButton = {
lazy var flipToFront: UIButton = {
That should solve the tap issue.
Why is my touch up inside event for my UIButton not being called?
Aha, I got it. It turns out the subview which contained the button (along with the other controls) had a height of 740 and the button was at a Y of 781. Moving the button up fixed the issue. Since everything was displaying correctly, I didn't think to check the subview's height.
Related Topics
How to Limit an iOS App Only to 4 Inch Screen Devices
Launching Viber App via Url Scheme on iOS
Swift - Image Data from Ciimage Qr Code/How to Render Cifilter Output
How to Pass Data from One Container to Another, Both Embedded in the Same Uiviewcontroller in Swift
How to Get Navigation Based Template Functionality in Swift Programming
Swift Uicolor Initializer - Compiler Error Only When Targeting Iphone5S
<Input Type="Number"/> Is Not Showing a Number Keypad on iOS
While Scrolling on an iOS Device, the Z-Index of Elements Isn't Working
How to Consecutively Present Two Alert Views Using Swiftui
How to Create Otp Verification Screen and Detect Delete Backward on Multiple Uitextfield Is Swift
Getter VS Computed Property. What Would Warrant Using One of These Approaches Over the Other
How Is Possible That "Display: Flex" and "Align-Items: Center" Do Not Work Anymore on My Iphone
Why Does CSS Background-Size: Cover Not Work in Portrait Mode on iOS
Dateformatter Returns Unexpected Date for Timezone
Convert String With Unknown Format (Any Format) to Date
Swift Formatting String to Have 2 Decimal Numbers If It Is Not a Whole Number