当部分 [Xamarin.iOS] 中只有一行时如何重新加载部分?

问题描述

我在 UITableView 部分有 1 行,我想删除该行试图更新表然后它给出了这个异常:

NSInternalInconsistencyException 原因:尝试删除并重新加载 相同的索引路径 ( {length = 2,path = 1 - 9223372036854775807})

代码

public void DeleteContact(NSIndexPath indexPath,UserData userData)
{
    DatabaseService.DeleteItem(userData.ID);

    listData();

    ListView.source = new TableSource(_itemdata,OnAddButtonClick,this);

    ListView.BeginUpdates();

    NSIndexPath[] rowsToReload = new NSIndexPath[]
    {
         NSIndexPath.FromrowSection(indexPath.Row,indexPath.Section)
    };

    var numberOfRowsInSection = ListView.NumberOfRowsInSection(indexPath.Section);

    if (numberOfRowsInSection == 1)
    {
        ListView.ReloadSections(NSIndexSet.FromIndex(indexPath.Section),UITableViewRowAnimation.Fade);
        ListView.DeleteSections(NSIndexSet.FromIndex(indexPath.Section),UITableViewRowAnimation.Fade);
        ListView.EndUpdates();
    }
    else
    {
        ListView.ReloadSections(NSIndexSet.FromIndex(indexPath.Section),UITableViewRowAnimation.Fade);
        ListView.EndUpdates();
    }
}

public void listData()
{
   List<UserData> listData = DatabaseService.GetAll();
   var sorted = listData.OrderBy(item => item.Name).ToList();
   _itemdata = sorted;
}

然后我尝试只更新表而不删除部分:

ListView.ReloadSections(NSIndexSet.FromIndex(indexPath.Section),UITableViewRowAnimation.Fade);
ListView.EndUpdates();

有了这个,它给出了这个例外:

NSInternalInconsistencyException 原因:尝试插入第 1 节 但更新后只有1个部分

最后我尝试调用 ListView.ReloadData();但这也不会更新 UITableView。

有人知道如何实现吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)