我在TableViewCell中使用了TableViewCell。所有的工作正常,并显示一切如预期。但是,如果我非常快地滚动TableView,项目(我在collectionView中使用了图像)从一个集合替换为来自另一个集合的items (图像),然后在视图上重写它(在代码中的调试模式很好,它只是显示它们)。
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;
}发布于 2019-12-11 16:02:43
这可能是因为UITableView中的单元重用系统。配置单元格时,是否正确设置数据?你叫CollectionView's reloadData()吗?
编辑:您应该在配置单元格的tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell中调用它。这样,每次重复使用单元格时,都会更新其内容。
编辑2:就像我说的,在设置表视图单元格时尝试添加集合视图reloadData()。您还必须清理数据源和委托,因为它是一个重用的单元格,因此它可能已经与另一个值一起使用了。
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;发布于 2020-01-03 09:12:42
Swift 5将此添加到您的自定义UITableViewCell类中。
override func prepareForReuse() {
collectionView.dataSource = nil
collectionView.delegate = nil
collectionView.reloadData()
collectionView.dataSource = self
collectionView.delegate = self
}https://stackoverflow.com/questions/59289635
复制相似问题