ここには迅速な解決策があります。 コレクションビューのデータソースをセットアップし、tableview委譲メソッドcellForRowAtIndexPathを使用してtableviewセルにデリゲートする必要があります。この後、collectionviewデータソースを使用し、tableveiewデータソースとデリゲートを確認したviewControllerにデリゲートメソッドをデリゲートします。
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
}
}
ここcell.setcollectionViewDataSourceDelegate(自己、forRow:indexPath.rom)ここmainViewControllerためのコードであるコードは、このドラッグ後のテーブルビューセルにテーブルビューのセルにcollectionview出口をcollectionviewデリゲートとデータソースを設定します。 tableViewセルに次のようにcollectionViewデリゲートを設定するmehod setcollectionViewDataSourceDelegateを追加します。
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()
}
}
このあなたにコレクションビューのデリゲートメソッドを使用しますが、コントローラ表示した後:明確な説明訪問このhttps://ashfurrow.com/blog/putting-a-uicollectionview-in-a-uitableviewcell-in-swift/
について
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)")
}
}
を
私はこれを見つけましたが、それはテーブル内の基本的なテーブルです。 http://iosstuff.wordpress.com/2011/06/29/adding-a-uitableview-viewable-a-uitableviewcell/ Table View内のCollection View(カスタムCellを使用)に変換するのは面倒ですが、これは役に立ちました。間違ったキーワードを探しているのですか? –
[このチュートリアル](http://ashfurrow.com/blog/putting-a-uicollectionview-in-a-uitableviewcell)はあなたが探しているものです。 –