TableView里面的UICollectionView没有填充单元格?

Ste*_*all 7 uitableview ios uicollectionview swift

我有一个tableView,行需要水平流动collectionViews.

我的tableView单元格中有一个collectionView,然后我像这样实例化它们:

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell: MyTableViewCell = tableView.dequeueReusableCellWithIdentifier("MyTableViewCell", forIndexPath: indexPath) as! MyTableViewCell
    let nibName = UINib(nibName: "CollectionCell", bundle: nil)
    cell.collectionView.registerNib(nibName, forCellWithReuseIdentifier: "CollectionCell")
    cell.collectionView.dataSource = self
    cell.collectionView.delegate = self

    return cell
}
Run Code Online (Sandbox Code Playgroud)

我正在尝试使用自动高度表视图行,我认为这可能会导致问题.如何将UITableViewAutomaticDimension与内部集合视图一起使用?

trd*_*son 7

这是在objective-c,但对我有用:

一世.在自定义单元格的.m文件中注册UICollectionViewCellnib,并指定布局详细信息(大小,间距等).

II.在保存tableView的VC中,其.m执行以下操作cellForRowAtIndexPath

 MyTableViewCell *cell = (MyTableViewCell*)[tableView dequeueReusableCellWithIdentifier:@"MyTableViewCellId" forIndexPath:indexPath];

    cell.collectionView.delegate = self;
    cell.collectionView.dataSource = self;
    cell.collectionView.tag = indexPath.row;

    [cell.collectionView reloadData];
Run Code Online (Sandbox Code Playgroud)

III.您可以使用UICollectionView委托方法中的标记来填充正确的信息

跳这有帮助.