TableViewCell 内的 CollectionView [英] CollectionView inside TableViewCell

查看:14
本文介绍了TableViewCell 内的 CollectionView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 TableViewCell 中使用了 CollectionView.一切正常,并按预期显示.但是,如果我非常快速地滚动 TableView,一个集合中的项目(我在 collectionView 中使用图像)将替换为另一个集合中的项目(图像)并在 View 上覆盖它(在代码中的调试模式下工作正常,它只是显示它们).

I used CollectionView inside TableViewCell. All works fine and shown all as expected. But if I scrolled the TableView very fast, items (i used images in collectionView) from one collection replaced with items (images) from another collection and override it on View (on Debug mode in code al works fine, its just displaying of them).

UITableView GetCell():

public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
    {
        var item = _view.Items[indexPath.Row];
        var cell = (MyTableCell)tableView.DequeueReusableCell("cell");
        cell.TextLabelView.Text = item.Title;
        cell.YesButtonView.Hidden = item.IsCategory;
        cell.NoButtonView.Hidden = item.IsCategory;
        if (item.IsImagePoint)
        {
            cell.ImagesCollectionView.DataSource = new ItemsDataSource(item.Images, cell.ImagesCollectionView);
            cell.ImagesCollectionView.Delegate = new ItemsDelegate(item, _view);
        }
        return cell;
    }

UICollectionView GetCell():

public override UICollectionViewCell GetCell(UICollectionView collectionView, NSIndexPath indexPath)
    {
            var cell = (ImageViewCell)_collectionView.DequeueReusableCell(new NSString("ImageViewCell"), indexPath);
            var image = _images[indexPath.Row];
            var imagePath = image.ThumbnailPath;
            if (!string.IsNullOrEmpty(imagePath))
            {
                cell.ImagePath = imagePath;
            }
            return cell;
    }

推荐答案

可能是因为 UITableView 中单元格的复用系统.您在配置单元时是否正确设置了数据?你调用CollectionViewreloadData()吗?

It's probably because of the reuse system of cells in UITableView. Do you set up properly your data when you configure the cell? Do you call CollectionView's reloadData()?

EDIT:你应该在 tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) ->UITableViewCell 在其中配置单元格.这样,每次重复使用单元格时,您都会更新其内容.

EDIT: You should call it in the tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell where you configure your cell. This way, each time a cell is reused, you update its content.

EDIT 2:就像我说的,在设置 tableview 单元格时尝试添加集合视图 reloadData().您还必须清理数据源和委托,因为它是一个重复使用的单元格,因此它可能已经与另一个值一起使用.

EDIT 2: Just like I said try to add the collection view reloadData() when you set up your tableview cell. You also have to clean your datasource and delegate, because it's a reused cell so it may already have been used with another value.

 if (item.IsImagePoint)
    {
        cell.ImagesCollectionView.DataSource = new ItemsDataSource(item.Images, cell.ImagesCollectionView);
        cell.ImagesCollectionView.Delegate = new ItemsDelegate(item, _view);
    }
 else
    {
        cell.ImagesCollectionView.DataSource = null;
        cell.ImagesCollectionView.Delegate = null;
    }

 cell.ImagesCollectionView.ReloadData()

 return cell;

这篇关于TableViewCell 内的 CollectionView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆