Ich möchte jedes allItems
für jedes Objekt in inventory
sehen, um in jeder Zeile angezeigt zu werden. Wie es jetzt ist, wo ich indexPathOfCollectionView
geschrieben habe, gibt es eine 0, um zu sehen, dass es tatsächlich funktioniert, aber ich weiß nicht, welche Variable ich schreiben sollte, um jedes allItems
aus dem inventory
zu sehen.UITableView dataSource aus dem Klassenobjekt innerhalb einer UICollectionViewCell
var inventory = [Item]()
class Item {
var name: String!
var allItems: [String]!
init(name: String, allItems: [String]) {
self.name = name
self.allItems = allItems
}
}
Sammlung Cell:
class ItemCollectionViewCell: UICollectionViewCell, UITableViewDelegate, UITableViewDataSource {
var inventory = [Item]()
@IBOutlet weak var testTableView: UITableView!
@IBOutlet weak var nameLabel: UILabel!
func configureCell(_ inventory: Item) {
nameLabel.text = inventory[indexPath.row]
testTableView.dataSource = self
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return inventory[indexPathOfCollectionView*].allItems.count
}
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var cell: UITableViewCell? = tableView.dequeueReusableCell(withIdentifier: "ItemsCell")
if(cell == nil){
cell = UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: "ItemsCell")
}
cell.textLabel?.text = inventory[indexPathOfCollection*].allItems[indexPath.row]
return cell
}
}
Dies ist in den viewController
class VC: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return inventory.count
}
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CollectionCellItem", for: indexPath) as! ItemCollectionViewCell
let it: Item!
it = inventory[indexPath.row]
cell.configureCell(it)
return cell
}
}
ist hier ein screenshot von dem, was ich
was wollen Sie genau? – iYoung
Um jedes einzelne eindeutige Array innerhalb von 'Item' in der' tableView' innerhalb der 'collectionViewCell' anzeigen zu können. Wie es jetzt ist, zeigt es nur das erste Objekt an, wie ich erwähnte, 0 in Inventar [0] zu schreiben. AllItems [indexPath.row]. Das 0 ist das Problem, und ich kann keine mögliche Lösung sehen – Christian
versuchen Sie 'inventory [indexPath.row] 'anstelle von' inventory [indexPathOfCollection *]' – iYoung