locked
UITableView delete row RRS feed

  • Question

  • User395623 posted

    Dear All,

    I am adding items to UITableView.New Item Adding is fine.It will be inserted at zero index. But i want to check if the new item provided is already in the list.If its already there,first remove it from the list and insert it in zero index.How to do it?

    ``` private void AddNewItemAsync(Item item) {

            Item result = fullItems.Find(x => x.BookId == item.BookId);
            if(result!=null)
            {
                ItemsTableView.BeginUpdates();
                fullItems.Remove(result);
                ItemsTableView.ReloadData();
        ItemsTableView.EndUpdates();            
       }
            item.NewItemFlag = true;
            fullItems.Insert(0, item);
            ItemsTableView.BeginUpdates();          
            ItemsTableView.InsertRows(new[] { NSIndexPath.Create(0, 0) }, UITableViewRowAnimation.Top);           
            ItemsTableView.EndUpdates();
        }
    

    ```

    Saturday, February 27, 2021 5:28 PM

All replies

  • User369978 posted

    Modify your code as below

    ``` private void AddNewItemAsync(Item item) {

           Item result = fullItems.Find(x => x.BookId == item.BookId);
            if(result!=null)
            {
                fullItems.Remove(result); 
            }
            item.NewItemFlag = true;
            fullItems.Insert(0, item);
            ItemsTableView.ReloadData();
        }
    

    ```

    Monday, March 1, 2021 5:31 AM