Hier ist die Lösung für schnelle. Sie müssen eine CollectionView-Datenquelle einrichten und in die TableView-Zelle delegieren, indem Sie die tabellenView-Delegierungsmethode cellForRowAtIndexPath verwenden. Verwenden Sie danach eine Datenquelle summaryview und delegieren Sie in einen viewController, in dem Sie die Tabellenviewer-Datenquelle und -Delegate bestätigt haben. Hier ist der Code für Mainviewcontroller:
extension MainViewController:UITableViewDataSource, UITableViewDelegate {
// .....do some table view setup like numberOfRowsInSection ......
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("yourReusecellIdentifier", forIndexPath: indexPath) as! yourCustomCell
cell.setCollectionViewDataSourceDelegate(self, forRow: indexPath.row)
return cell
}
}
hier cell.setcollectionViewDataSourceDelegate (self, forRow: indexPath.rom) -Code setzt einen Kollektion Delegierten und Datenquelle in der Tabellendarstellung Zelle nach diesem ziehen, um die Steckdose zu Kollektiontableview Zelle. In der Tableview Zelle ein mehod setcollectionViewDataSourceDelegate hinzufügen Collection Delegierten wie folgt zu setzen:
class yourCustomCell: UITableViewCell {
//MARK:- Properties
@IBOutlet weak var collectionView: UICollectionView!
//MARK:- initialization methods
override func awakeFromNib() {
super.awakeFromNib()
setupView()
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
}
//MARK:- Setup collectionView datasource and delegate
func setCollectionViewDataSourceDelegate
<D: protocol<UICollectionViewDataSource, UICollectionViewDelegate>>
(dataSourceDelegate: D, forRow row: Int) {
collectionView.delegate = dataSourceDelegate
collectionView.dataSource = dataSourceDelegate
collectionView.tag = row
collectionView.reloadData()
}
}
Nach dieser Verwendung der Sammlung Ansicht Delegatmethode in Sie Controller anzuzeigen:
extension MainViewController: UICollectionViewDelegate, UICollectionViewDataSource {
func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 2
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 5
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("collectionViewReuseIdentifier", forIndexPath: indexPath) as! YourCollectionViewCustomCell
.......cell configure....
return cell
}
}
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
print("get selected collectionview itemindex \(indexPath.row)")
}
}
Für klare Erklärung Besuch diesen https://ashfurrow.com/blog/putting-a-uicollectionview-in-a-uitableviewcell-in-swift/
Ich habe dies gefunden, aber es ist eine grundlegende Tabelle in einer Tabelle. http://iosstuff.wordpress.com/2011/06/29/adding-a-uitableview-inside-a-uitableviewcell/ und es in Collection-Ansicht (mit benutzerdefinierten Zelle) in einer Tabellenansicht zu übersetzen ist schwierig, obwohl es hilfreich war . Ich frage mich, ob ich nach den falschen Schlüsselwörtern suche? –
[Dieses Tutorial] (http://ashfurrow.com/blog/putting-a-uicollectionview-in-a-uitableviewcell) ist genau das, was Sie suchen. –