0
Ich habe Tableview:Nicht wiederverwenden Daten mit ReusableCell von Collection
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cellTime", for: indexPath) as! TimeViewCell
let showHour = self.infoWripper.sorted(by: { $0.hour < $1.hour })[indexPath.row]
cell.labelTime.text = showHour.showHour()
cell.dataForShow = showHour.showFullTime()
return cell
}
Zelle von Tableview Inhalte UICollectionView
mit Zellen.
class TimeViewCell: UITableViewCell {
@IBOutlet weak var labelTime: UILabel!
var dataForShow = [String]()
@IBOutlet weak var collectionView: UICollectionView!
override func awakeFromNib() {
super.awakeFromNib()
collectionView.delegate = self
collectionView.dataSource = self
}
}
extension TimeViewCell: UICollectionViewDelegate, UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return dataForShow.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CollectionCell", for: indexPath) as! CustomCollectionCell
cell.labelCollection.text = dataForShow[indexPath.row]
//heightForCell = collectionView.contentSize.height
return cell
}
}
class CustomCollectionCell: UICollectionViewCell {
@IBOutlet weak var labelCollection: UILabel!
}
Wenn ich VC mit Tisch öffnen - Ansicht ist in Ordnung, aber wenn ich beginne Scrollen - ich sehe, dass die Daten nicht korrekt (Wiederverwendung), aber ich kann nicht meinen Fehler finden. vor blättern:
nach:
ja! wirklich gut funktioniert, danke! –