【问题标题】:CollectionView.DeleteItems throws exception NSInternalInconsistencyExceptionCollectionView.DeleteItems 抛出异常 NSInternalInconsistencyException
【发布时间】:2015-07-28 00:06:45
【问题描述】:

当我尝试在我的 UICollectionView 上调用 DeleteItems 时,我遇到了这个异常。我搜索了一下,大多数人都说他们通过在调用 DeleteItems 后不调用 CollectionView 上的 ReloadData 来解决这个问题,但我知道我没有调用它。我什至覆盖了它并在 ReloadData 上设置了一个断点并确认它没有被调用。

this.InvokeOnMainThread(() => 
{
    CollectionView.DeleteItems (new NSIndexPath [] { indexPath });
});

Objective-C 抛出异常。名称:NSInternalInconsistencyException 原因:无效更新:第 0 节中的项目数无效。更新后现有节中包含的项目数 (5) 必须等于更新前该节中包含的项目数 (5),加上或减去从该部分插入或删除的项目数(0 插入,1 个删除),加上或减去移入或移出该部分的项目数(0 移入,0 移出)。

【问题讨论】:

标签: ios xamarin uicollectionview


【解决方案1】:

看起来我需要在调用 DeleteItems 之前更新与我的数据源相关联的列表:

this.InvokeOnMainThread(() => 
{
    this.MyList.RemoveAt(indexPath.Row);
    CollectionView.DeleteItems (new NSIndexPath [] { indexPath });
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-09-02
    • 2013-05-24
    • 1970-01-01
    • 2011-05-30
    • 1970-01-01
    • 2011-02-25
    相关资源
    最近更新 更多