如何在UITableViewcells中使用UICollectionViewCells

时间:2017-09-11 04:18:42

标签: ios xcode uitableview swift3 uicollectionview

我的一个TableViewCell必须有CollectionView,而另一个是自定义的TableViewcells,它们有不同数量的标签和ImageViews.Here是来自我的ViewController的代码:

func tableView(_tableView:UITableView,numberOfRowsInSection section: Int)->Int{
    return seachable.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    if seachable[indexPath.row].first.name != nil{
        let cell  = tableView.dequeueReusableCell(withIdentifier: "Cell1", for: indexPath) as! FristTableViewCell
        cell.firstOne.text = seachable[indexPath.row].first.name
        return cell
    }
    .........and so on
    else {
        let cell=tableView.dequeueReusableCell(withIdentifier:"Cell4",for: indexPath) as! FourTableViewCell
        cell.collectioinView1.reloadData()
        return cell
    }

下面是带有CollectionView的TableViewCell代码:

extension FourTableViewCell : UICollectionViewDataSource,UICollectionViewDelegate
{
    func numberOfSections(in collectionView: UICollectionView) -> Int {
        return 1
    }
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 10

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

        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CollectionCell", for: indexPath) as! OneCollectionViewCell
        cell.collectionCellLabel.text = "a"
        return cell
    }
}

我遇到的错误是:未定义UICollectionViewFlowLayout的行为,因为:

0 个答案:

没有答案