Ich habe UICollectionView mit benutzerdefinierten Zelle (xib-Datei), schaffe ich das Kollektion anzuzeigen, aber ich schaffte es nicht, zu erkennen, wenn ich auf eine Zelle tippen mit der Funktion:Swift Collection didSelectItemAtIndexPath funktioniert nicht
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath){
Normalerweise gelingt mir das, aber dieses Mal weiß ich nicht, warum es nicht funktioniert. Eigentlich bin ich mit dieses Pods "https://cocoapods.org/pods/SACollectionViewVerticalScalingFlowLayout"
Mein Code ist:
class ProjectsController: UIViewController {
@IBOutlet weak var collectionViewGridFormat: UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
collectionViewGridFormat.registerNib(UINib(nibName: "ProjectsGridFormatCell", bundle: nil), forCellWithReuseIdentifier: "cellProjectGrid")
...
}
}
extension ProjectsController: UICollectionViewDataSource, UICollectionViewDelegate {
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 30
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell : ProjectsGridFormatCell = collectionView.dequeueReusableCellWithReuseIdentifier("cellProjectGrid", forIndexPath: indexPath) as! ProjectsGridFormatCell
cell.lblProjectName.text = "Test project"
return cell
}
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath){
print("aa")
}
}
Aber wenn ich auf eine Zelle tippen, "print (" aa ")" wird nicht angezeigt.
Habe ich genug Informationen gegeben? :)
Danke für Ihre Hilfe !! : D
Grüße,
Haben Sie Ihren View-Controller als Delegat der Sammlungsansicht festgelegt? Sie müssen beides festlegen - Delegat und Datenquelle. – almas