当我在Xamarin.iOS中删除tableview的特定行时。 tableview变成了以前的样子。

时间:2018-08-17 05:49:22

标签: ios xamarin.ios

我正在xamarin.ios中工作。下面附有代码

public override void CommitEditingStyle (UITableView tableView,UITableViewCellEditingStyle editingStyle, Foundation.NSIndexPath indexPath){

      switch (editingStyle) {
             case UITableViewCellEditingStyle.Delete:
             // delete the row from the table
             tableView.DeleteRows (new NSIndexPath[] { indexPath }, UITableViewRowAnimation.Fade);
             break;
             case UITableViewCellEditingStyle.None:
             break;
}}

当我滑动以进行删除时它起作用。但是,当我按下一个新的ViewController并返回时,没有任何变化。

我是iOS新手。希望有人可以提供帮助。

1 个答案:

答案 0 :(得分:1)

我想您刚刚刷新了界面。这还不够。 使用代码

    // remove the item from the underlying data source
    tableItems.RemoveAt(indexPath.Row);
    // delete the row from the table
    tableView.DeleteRows (new NSIndexPath[] { indexPath }, UITableViewRowAnimation.Fade);

同时,您应该从数据源中删除相应的数据。