2017-12-05 21 views
2

私は次のような多次元配列を持っていますが、どのようにしてテーブルビュー/ビューセルのコレクションビューの配列を渡すことができますか?テーブルビューのセル内のコレクションビューで多次元配列を渡す方法は?

let array = [["abc " , " bce "] , ["a "] , ["abc " , " abce " , " a "] , []] 

最初のセルの最初の配列オブジェクト、2番目のセルの2番目の配列オブジェクト、および連続を必要とします。

+0

は、私はあなたがセクションの内側セクションと、細胞が必要だと思う。この方法のように実装することができますが、 '使い、単純な配列にそれを変換したい場合は、セル –

+0

としてセクションとして各配列とそれぞれの値let arr = array.flatMap {$ 0} 'またはセクションtableviewを使用できます –

答えて

1

あなたは

extension YourViewController : UICollectionViewDelegate,UICollectionViewDataSource { 

    func numberOfSections(in collectionView: UICollectionView) -> Int { 
     return array.count 
    } 

    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 

     return array[section].count 
    } 

    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 
     let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CollectionCell", for: indexPath) 
     let string = array[indexPath.section][indexPath.item] 
     return cell 
    } 

    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { 
     let selectedString = array[indexPath.section][indexPath.item] 
    } 

}