Кнопки в collectionViewCell не вызывают функции - PullRequest
0 голосов
/ 24 сентября 2019

Я создал кнопку в дополнительной ячейке collectionView в качестве заголовка и добавил кнопку с целью, но она не вызывает функцию при нажатии.Что я делаю неправильно?

Ниже находится созданная мной кнопка и ее целевая функция в классе ячеек.

let dummyButton :UIButton = {
    let button = UIButton(type: .system)
    button.setTitle("Dummy", for: .normal)
    button.layer.cornerRadius = 3
    button.layer.borderWidth = 1
    button.titleLabel?.font = UIFont.systemFont(ofSize: 12)
    button.tintColor = UIColor.brown
    button.addTarget(self, action: #selector(handleTrash), for: .touchUpInside)
    return button
}() 


@objc func handleTrash (){
    print("It worked this time around so what was going on?")
}

Я написал все это в подклассе CollectionView Cell.Пожалуйста, помогите

1 Ответ

0 голосов
/ 24 сентября 2019

Добавить отправителя

button.addTarget(self, action: #selector(handleTrash(_:)), for: .touchUpInside)

@objc func handleTrash (_ sender: UIButton){
    print("It worked this time around so what was going on?")
}
...