Forum Xamarin.iOS

UITableView delete row

rajesh81rajesh81 Member ✭✭
edited February 27 in Xamarin.iOS

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();
        }
Tagged:

Answers

  • ColeXColeX Member, Xamarin Team Xamurai

    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();
            }
    
Sign In or Register to comment.