igongora / UIDropDown

An elegant dropdown for iOS written in Swift.
MIT License
87 stars 17 forks source link

Can not be selected when added inside UICollectionViewCell #5

Closed johnyluyte closed 6 years ago

johnyluyte commented 7 years ago

Hello,

When I added UIDropDown inside my UICollectionViewCell. It can not be selected. It doesn't response to user tap or click.

class MyCell: UICollectionViewCell {
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupViews()
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    setupViews(){
        drop = UIDropDown(frame: CGRect(x: 0, y: 0, width: 80, height: 30))
        drop.center = CGPoint(x: 0, y: 0)
        drop.placeholder = "select your country"
        drop.options = ["Mexico", "USA", "England", "France", 
        drop.didSelect { (option, index) in
            print("You just select: \(option) at index: \(index)")
        }
        drop.tableHeight = 200
        drop.hideOptionsWhenSelect = true
        drop.animationType = UIDropDownAnimationType(rawValue: 0)!
        addSubview(drop)
    }
}

I've used UIDropDown in my other project. It works really great. Thanks you! But I don't know what I'm doing wrong in this case.

igongora commented 7 years ago

Hi @johnyluyte , quick question. Are you using the "initWithFrame" to initialize your cell?. It looks that the method "setupViews" only gets called when you initialize from "initWithFrame"

johnyluyte commented 7 years ago

@igongora Yes I did, the UIDropDown did show on the view, so I think the method "setupViews" is indeed being called. The problem is that even though UIDropDown did show on the view, but it didn't react to user taps.

I suppose this has something to do with UIGestureRecognizer. My project is quiet big and there might be some conflict between Gesture Event Listeners within objects. If UIDropDown did work on UICollectionViewCell for other people, than this issue can be closed. I'll look into my project. Thanks you!