2017-07-01 6 views
0

私はcollectionView sectionHeader内にtableViewを配置しようとしています。私はストーリーボードのヘッダーにtableViewを追加して、そのクラスをtableViewController.swiftに設定しようとしましたが、うまくいきませんでした。 (私はスウィフトを使用しています)セクションの中にtableViewを置く方法ヘッダー

+1

ヘッダーセクション内にtableviewを置いて何を達成しようとしていますか?それをコレクションビューの上に置くのはなぜですか? –

+0

collectionViewにはアイコンがあり、ヘッダーはユーザーがスワイプできるイメージを表示するためのものです。私は別のcollectionViewを画像を表示するtableViewの1つのセルの中に入れようとしていました。私が行ったもう一つのセル、いくつかのボタン。私はそれをcollectionViewでスクロールするようにヘッダに入れようとしていました。 @DarkInnocence –

+0

私はそれを最初にコードしてうまくいけばそれは働く.. –

答えて

0

ちょっと試してみたら、正しく動作するようにしました。 最初にヘッダを作成してから、tableViewのIBOutletを作成しました。 次に、tableViewControllerがセットアップされ、dataSourceに接続され、awakeFromNibでデリゲートされ、完了したようなヘッダファイルを設定するだけです。

class HomeHeader: UICollectionReusableView, UITableViewDataSource, UITableViewDelegate { 


    @IBOutlet weak var tableView: UITableView! 


    override func awakeFromNib() { 

     tableView.delegate = self 
     tableView.dataSource = self 
     //tableView.backgroundColor = UIColor.clear 
    } 

    func numberOfSections(in tableView: UITableView) -> Int { 

     return 1 //number of sections 
    } 


    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 


     return 5 //number of cells 
    } 

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
     let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as UITableViewCell 
     cell.textLabel?.text = "test" 
     // cell.backgroundColor = UIColor.clear 

     return cell 
    } 


    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 


    } 



} 
関連する問題