Hallo Ich möchte Zelle Titel in UICollectionView
, ich habe 1 Zelle innerhalb UICollectionView
Zelle haben Kategorien Array, wenn ich auf UICollectionView
Element Ich möchte Zelle Titel bekommen. Meine Codes hier.Zwei gerichtete Zelle innerhalb der Sammlungsansicht, wie man Zellentitel bekommt?
View-Controller-Zelle
import UIKit
class ViewController: UIViewController {
var categories = ["A", "B", "C", "D", "E"]
}
extension ViewController : UITableViewDelegate { }
extension ViewController : UITableViewDataSource {
func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return categories[section]
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return categories.count
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell") as! CategoryRow
return cell
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
print(indexPath.row)
}
}
UICollectionView
import UIKit
class CategoryRow : UITableViewCell {
@IBOutlet weak var collectionView: UICollectionView!
}
extension CategoryRow : UICollectionViewDataSource {
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 12
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("videoCell", forIndexPath: indexPath) as! VideoCell
return cell
}
}
extension CategoryRow : UICollectionViewDelegateFlowLayout {
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
let itemsPerRow:CGFloat = 4
let hardCodedPadding:CGFloat = 5
let itemWidth = (collectionView.bounds.width/itemsPerRow) - hardCodedPadding
let itemHeight = collectionView.bounds.height - (2 * hardCodedPadding)
return CGSize(width: itemWidth, height: itemHeight)
}
//MARK :- UICollectionViewDelegate
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
print(indexPath.row) // HERE gives collection view number when clicked BUT I WANT TO Get cell title which inside categories ARRAY example: A/3, B/5
}
}
Unterseite I mit
print (indexPath.row) markiert // HIER gibt Zahl Sammlung Ansicht, wenn darauf geklickt, aber ich möchte Zelle Titel erhalten, die innerhalb Kategorien ARRAY Beispiel: A/3, B/5
Ich möchte Action sehen, danke Ihrer Hilfe!
hallo ich habe, aber wenn ich gibt Ausgang wie A/5, A/3 geklickt haben, A/7, jede Zelle A gibt, aber ich clicked C, aber gibt alle von ihnen A – SwiftDeveloper
Ich habe vergessen, Sie müssen 'prepareforReuse' Methode in der Zelle hinzufügen, aktualisierte Antwort – iSashok
Ich fügte hinzu, aber die gleiche gibt Ausgabe alle, A/2 wie – SwiftDeveloper