Hey, je suis nouveau à la programmation et mon problème est, j'ai un UICollectionViewController
avec 4 cellules qui sont scrollable horizontal. A l'intérieur de la 4ème cellule, j'ai un UIButton
(optionsButton
) sur un UIView
(ProfileContainerView
).Comment présenter un ViewController après avoir appuyé sur un bouton à l'intérieur d'un CollectionViewCell
Le UIViewController
Je souhaite présenter est appelé ProfileEditViewController
et est mis en place dans Main.storyboard
.
Comment puis-je présenter un UIViewController
après avoir appuyé sur ce bouton?
ProfileCell:
class ProfileCell: UICollectionViewCell {
let profileContainerView: UIView = {
let view = UIView()
return view
}()
lazy var optionsButton: UIButton = {
let btn = UIButton(type: .custom)
btn.setImage(#imageLiteral(resourceName: "Settings"), for: UIControlState.normal)
btn.addTarget(self, action: #selector(handleOptionsButton), for: UIControlEvents.touchUpInside)
return btn
}()
@objc func handleOptionsButton() {
print("Button pressed")
}
}
HomeViewController:
class HomeViewController: UICollectionViewController, UICollectionViewDelegateFlowLayout {
let profileCelId = "profileCell"
override func viewDidLoad() {
super.viewDidLoad()
setupSwipeView()
}
func setupSwipeView() {
collectionView?.register(UICollectionViewCell.self, forCellWithReuseIdentifier: cell)
collectionView?.register(ProfileCell.self, forCellWithReuseIdentifier: profileCelId)
}
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if indexPath.item == 3 {
return collectionView.dequeueReusableCell(withReuseIdentifier: profileCelId, for: indexPath)
}
return cell
}
}
Vérifiez ceci: https://stackoverflow.com/questions/43766963/swift-action-button-inside-a-collectionviewcell – Amit