다음은 신속한 해결책입니다. collectionview 데이터 소스를 설정하고 tableview 위임 메소드 cellForRowAtIndexPath를 사용하여 tableview 셀에 위임해야합니다.이 후 collectionview 데이터 소스를 사용하고 tableveiew 데이터 소스 및 위임을 확인한 viewController에 위임 메소드를 위임해야합니다. 여기 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
}
}
cell.setcollectionViewDataSourceDelegate (자기가 forRow : indexPath.rom) 코드는 드래그 이후의 tableview 셀에 collectionview 콘센트 테이블 뷰 셀에 collectionview 대리자와 소스를 설정한다. 있는 tableView 셀에 다음과 같이 collectionView 대리자를 설정하는 mehod setcollectionViewDataSourceDelegate을 추가
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)")
}
}
명확한 설명 방문이 https://ashfurrow.com/blog/putting-a-uicollectionview-in-a-uitableviewcell-in-swift/
를 들어이 사용 컬렉션 뷰 대리자 메서드 후
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()
}
}
당신이 컨트롤러를 볼에
이걸 찾았지만 테이블의 기본 테이블입니다. http://iosstuff.wordpress.com/2011/06/29/adding-a-uitableview-inside-a-uitableviewcell/ Table View 내에서 Collection View (맞춤형 셀 포함)로 변환하는 것이 유용하지만 까다 롭습니다. . 나는 틀린 핵심어를 찾고 있는지 궁금해하고 있습니까? –
[이 튜토리얼] (http://ashfurrow.com/blog/putting-a-uicollectionview-in-a-uitableviewcell) 정확히 찾고있는 것입니다. –