locked
Collection View Cell Click RRS feed

  • Question

  • User389827 posted

    I'm trying to implement Collection View in Xamarin iOS using CollectionViewDataSource and Collection view Cell classes.

    My Requirement is to change the colour of the selected cell.

    I tried using ``` public override void ItemSelected(UICollectionView collectionView, NSIndexPath indexPath) {

    }

    ```

    but nothing happened.

    Is their a way to identify the cell clicked event in collection View

    Kindly help me on this.

    Thanks

    Thursday, September 3, 2020 2:59 PM

Answers

  • User369978 posted

    First get the current selected cell and then change its contentView's backgroundColor .

         public override void ItemSelected(UICollectionView collectionView, NSIndexPath indexPath)
        {
            var cell = collectionView.CellForItem(indexPath);
            cell.ContentView.BackgroundColor = UIColor.Red;
    
        }
    

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Friday, September 4, 2020 3:14 AM