微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决当部分 [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 举报,一经查实,本站将立刻删除。