Comments (8)
ASCollectionViewDelegate
extends from UICollectionViewDelegate
and you can use any function provided by UICollectionViewDelegate
. In your case it is
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath)
.
from ascollectionview.
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.
Can you display any item on collection view?
from ascollectionview.
YES!
from ascollectionview.
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.
Check your User Interaction Enabled
checkbox for the collection view from your xib file or storyboard. It should be selected.
from ascollectionview.
Did you find the reason and fix it already?
from ascollectionview.
YES!
I decided to create Xib file not using custom view class.
Tanks a lot .
from ascollectionview.
Related Issues (7)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ascollectionview.