简体   繁体   中英

How to call a cell’s function when a scrollViewDidEndDecelerating occurs from UiCollectionView

  cell.callingApi(featurePost: featurePost)
  cell.mainImageView.imageChangeByMotion()

  func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {

  }

How to call a function Defined inside UICollectionViewCell from it's CollectionView for a particular cell when a scrollViewDidEndDecelerating occurs Swift

I agree with Khalid Afridi 's answer and here is the code that would help you do that:

for i in 0 ..< yourCollectionView.numberOfItems(inSection: 0) {
            if let cell = yourCollectionView.cellForItem(at: IndexPath(row: i, section: 0)) as? YourCustomCollectionViewCell {
                cell.yourFunction()
            }
        }

Note: If you know the IndexPath value of the cell you are trying to access there is no need to loop all the cells. Also don't forget to replace section value with the section that contains your cell.

You have to find your cell first. Easiest will be using indexPath to get the exact cell you want. Once you have a reference to that cell then you can call any function from that cell.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM