2013-05-20 1 views
7

배열에서 내용을 가져 오는 사용자 정의 셀이있는 테이블보기가 있습니다.이 모든 것이 잘됩니다. 이 콘텐츠에 다양한 사용자 정의 표보기 셀에 다양한 썸네일 이미지 컬렉션보기를 추가하고 싶습니다.컬렉션 테이블을 사용자 정의 테이블보기에 포함하십시오.

스토리 보드의 맞춤 셀에 컬렉션을 추가했습니다. 나는 Collection을 Custom Cell.m에 링크했다. 콜렉션 사용자 정의 셀을 생성하고 이미지를 링크했습니다.

콜렉션 뷰를 빌드하는 메소드가 사용자 정의 테이블 셀에 배치되어야하는지 확실하지 않습니다. View Controller .엠? Story Board의 이미지가 있습니다. 사용자 정의 테이블 셀을 볼 수 있습니다. 그리고 그 아래쪽에 (너무 명확하지 않습니다) 컬렉션 뷰 (가로 스크롤)로 이미지를 채우고 싶습니다. 정보가 누락되면 유감스럽게도 어떤 정보가 도움이되는지 확신 할 수 없습니다.

Picture of Custom Table Cell

+0

이걸 찾았지만 테이블의 기본 테이블입니다. http://iosstuff.wordpress.com/2011/06/29/adding-a-uitableview-inside-a-uitableviewcell/ Table View 내에서 Collection View (맞춤형 셀 포함)로 변환하는 것이 유용하지만 까다 롭습니다. . 나는 틀린 핵심어를 찾고 있는지 궁금해하고 있습니까? –

+0

[이 튜토리얼] (http://ashfurrow.com/blog/putting-a-uicollectionview-in-a-uitableviewcell) 정확히 찾고있는 것입니다. –

답변

4

당신은 사용자 정의 UITableViewCell 클래스 내부의 UICollectionViewDelagateDataSource을 넣어해야합니다.

여기에 nice tutorial입니다.

테이블 뷰 셀 내부의 tableview에 관한 것이지만 아이디어는 꽤 비슷합니다.

행운을 빌어 요!

+0

많은 감사합니다. 나는 한번 살펴 보겠습니다. –

+0

좋아 보인다. 스크롤 뷰를 추가 한 다음 서브 뷰를 배치하고 각 뷰에 제스처를 추가했습니다. 이 방법이 효과적이지만 귀하의 방법이 더 빠를 것이라고 생각합니다. –

2

다음은 신속한 해결책입니다. 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() 
} 
} 

당신이 컨트롤러를 볼에