Giter Club home page Giter Club logo

Comments (8)

abdullahselek avatar abdullahselek commented on June 7, 2024

ASCollectionViewDelegate extends from UICollectionViewDelegateand you can use any function provided by UICollectionViewDelegate. In your case it is
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath).

from ascollectionview.

sensuikan1973 avatar sensuikan1973 commented on June 7, 2024

Tanks for your reply.

I tried it, but I couldnn't...
Could you give me advice ?
My code cant't fire 「collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath)」.

My code is ↓

class VC_Question: UIViewController, ASCollectionViewDataSource, ASCollectionViewDelegate {
    
    @IBOutlet weak var collectionView: ASCollectionView!
    var numberOfItems: Int = 20
    let collectionElementKindHeader = "Header"
    let collectionElementKindMoreLoader = "MoreLoader"
    
    override func viewDidLoad() {
        super.viewDidLoad()

        collectionView.delegate = self
        collectionView.asDataSource = self
    }
    
    // MARK: ASCollectionViewDataSource
    func numberOfItemsInASCollectionView(_ asCollectionView: ASCollectionView) -> Int {
        return numberOfItems
    }
    
    func collectionView(_ asCollectionView: ASCollectionView, cellForItemAtIndexPath indexPath: IndexPath) -> UICollectionViewCell {
        let questionCell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! QuestionCell
        return questionCell
    }
    
    func collectionView(_ asCollectionView: ASCollectionView, parallaxCellForItemAtIndexPath indexPath: IndexPath) -> ASCollectionViewParallaxCell {
        let parallaxCell = collectionView.dequeueReusableCell(withReuseIdentifier: "parallaxCell", for: indexPath) as! ParallaxCell
        return parallaxCell
    }
    
    func collectionView(_ asCollectionView: ASCollectionView, headerAtIndexPath indexPath: IndexPath) -> UICollectionReusableView {
        let header = collectionView.dequeueReusableSupplementaryView(ofKind: ASCollectionViewElement.Header, withReuseIdentifier: "header", for: indexPath)
        return header
    }
    
    // MARK: ASCollectionViewDelegate
    func loadMoreInASCollectionView(_ asCollectionView: ASCollectionView) {
        print("loadMore")
        if numberOfItems > 30 {
            collectionView.enableLoadMore = false
            return
        }
        numberOfItems += 10
        collectionView.loadingMore = false
        collectionView.reloadData()
    }
    
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        print("aaa")
    }
    
}

from ascollectionview.

abdullahselek avatar abdullahselek commented on June 7, 2024

Can you display any item on collection view?

from ascollectionview.

sensuikan1973 avatar sensuikan1973 commented on June 7, 2024

YES!

2018-02-24 18 29 39

from ascollectionview.

sensuikan1973 avatar sensuikan1973 commented on June 7, 2024

I am sorry to give you trouble
I catch the reason
My custom view class...

Tanks a lot for replying me!!

import UIKit

class CustomCellView: UICollectionViewCell {
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        loadFromNib()
        afterInit()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        loadFromNib()
        afterInit()
    }
    
    func afterInit(){}
    
    override func prepareForInterfaceBuilder() {
        loadFromNib()
    }
    
    private func loadFromNib() {
        
        let nib = UINib(nibName: String(describing: type(of: self)), bundle: Bundle(for: type(of: self)))
        let view = nib.instantiate(withOwner: self, options: nil).first as! UICollectionViewCell
        
        view.frame = bounds
        addSubview(view)
        
        view.translatesAutoresizingMaskIntoConstraints = false
        addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|[view]|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: ["view": view]))
        addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|[view]|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: ["view": view]))
        
    }
    
}

from ascollectionview.

abdullahselek avatar abdullahselek commented on June 7, 2024

Check your User Interaction Enabled checkbox for the collection view from your xib file or storyboard. It should be selected.

from ascollectionview.

abdullahselek avatar abdullahselek commented on June 7, 2024

Did you find the reason and fix it already?

from ascollectionview.

sensuikan1973 avatar sensuikan1973 commented on June 7, 2024

YES!
I decided to create Xib file not using custom view class.

Tanks a lot .

from ascollectionview.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.