반응형
간단합니다.
@objc 메서드 만들고 버튼에서 addTaget 설정만 해주면 됩니다.
1. 컬렉션뷰 셀 부분에 addTaget주기
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: CollectionViewCell.identifier, for: indexPath) as! CollectionViewCell
cell.goBtn.addTarget(self, action: #selector(self.goBtnClicked), for: .touchUpInside) //addTarget
cell.goBtn.tag = indexPath.row
return cell
}
2.@objc 메서드 만들기
@objc func goBtnClicked(_ sender: UIButton) {
print("바로가기 클릭")
}
반응형
'iOS > UIKit' 카테고리의 다른 글
[Swift/UIKit] UIColor를 HexString으로 받는 Extension (0) | 2024.07.19 |
---|---|
[UIKit] App Delegate와 Scene Delegate (0) | 2024.06.05 |
[UIKit] translatesAutoresizingMaskIntoConstraints (0) | 2023.10.18 |
헷갈리는 Auto Layout 정리하자. (0) | 2023.07.16 |
[Swift/UI Kit] 'SideMenu'라이브러리 적용 (코드로만)feat.SnapKit (1) | 2023.07.01 |