将数组从UIViewController分配给Custom UITableViewCell类

时间:2017-03-13 09:01:35

标签: ios uitableview swift3 uicollectionview

我在swift 3中处理一个项目,它在UItableViewCell中包含一个UICollectionview。因此,我有UIViewController,UITableViewCell,UICollectionViewCell的三个类。类的代码如下所示。

的UIViewController

extension ViewController : UITableViewDelegate, UITableViewDataSource {

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

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

        return 1
    }
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{


        let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! TableViewCell

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

    }
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {

        return 160
    }

    func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {

        return (section%2 == 0) ? "Games":"Love"
    }

的UITableViewCell

extension TableViewCell: UICollectionViewDelegate, UICollectionViewDataSource {


func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    return imageNames.count

}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {


    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CollectionViewCell", for: indexPath) as! CollectionViewCell



    cell.naeLabel.text = imageNames [indexPath.row]


    return cell

}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {


    let clickedIndex = imageNames[indexPath.row]

    print(clickedIndex)


}

}

我的要求是将数组从UIViewController传递给UITableViewCell。我怎么能实现这个目标?

0 个答案:

没有答案