TenViewController Code:
class TenViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource { var selectedCell: UICollectionViewCell! var arrayLocation = ["aaa", "bbb", "ccc", "ddd", "eee"] var myCollectionView: UICollectionView! func numberOfSections(in collectionView: UICollectionView) -> Int { return 1 } func collectionView(_ collectionView: UICollectionView,numberOfItemsInSection section: Int) -> Int { return arrayLocation.count }
collection delegate
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! MyCollectionViewCell cell.backgroundColor = UIColor.white cell.titleLabel?.text = arrayLocation[indexPath.row] cell.titleLabel.font = UIFont.systemFont(ofSize: 24) return cell }
I try to use this function, but it does not work
func collectionView(_ collectionView: UICollectionView,didDeselectItemAt indexPath: IndexPath) { myCollectionView.deselectItem(at: indexPath, animated: false) } override func viewDidLoad() {
MyCollectionViewCell Code
class MyCollectionViewCell: UICollectionViewCell { var titleLabel:UILabel! override init(frame: CGRect) { super.init(frame: frame)
I would like to deselect a cell and what should I do?
Can anyone help me, thanks mate !!
How to make a button you can select the whole cell?
source share