How can I update my indexPath after deleting a Row in a TableView?
<p>I'm new to <code>Xamarin</code> and trying to make some basic todolist iOS app.</p>

<p>After struggling for a while with <code>TableViews</code>, I now have a TableSource, and custom cells containing a <code>UISwitch</code>.</p>

<p>My goal is, when the user activate the <code>UISwitch</code>, the cell is deleted for the <code>TableView</code>. To do that I created some custom event in my custom cell.</p>

<pre><code>public partial class TodoTableViewCell : UITableViewCell
{
    public delegate void DeleteTodoEventHandler(UITableView tableView, NSIndexPath indexPath);
    public event DeleteTodoEventHandler DeleteTodo;

    partial void DeleteTodoEvent(UISwitch sender)
    {
        if (DeleteTodo != null)
            DeleteTodo(null, new NSIndexPath());
    }

    public TodoTableViewCell(IntPtr p):base(p)
    {

    }

    public TodoTableViewCell(string reuseIdentifier) : base(UITableViewCellStyle.Default, reuseIdentifier)
    {

    }

    public void UpdateCell(TodoItem Item)
    {
        TodoLabel.Text = Item.Name;
        DateLabel.Text = Formating.formatDate(Item.Date);
        HourLabel.Text = Formating.formatTime(Item.Date);
    }
}
</code></pre>

<p><strong>DeleteTodoEvent</strong> is called when the user activate the <code>UISwitch</code>. Here is my tablesource :</p>

<pre><code>public class TableSource : UITableViewSource
{

    List&lt;TodoItem&gt; TableItems;
    string CellIdentifier = "TodoCell";

    ...

    public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
    {
        TodoTableViewCell cell = tableView.DequeueReusableCell(CellIdentifier) as TodoTableViewCell;
        TodoItem item = TableItems[indexPath.Row];

        //---- if there are no cells to reuse, create a new one
        if (cell == null)
        { 
            cell = new TodoTableViewCell(CellIdentifier);
        }

        cell.DeleteTodo += (table, index) =&gt; DeleteTodoHandler(tableView, indexPath);

        cell.UpdateCell(item);

        return cell;
    }

    ...

    private void DeleteTodoHandler(UITableView tableView, NSIndexPath indexPath)
    {
        TableItems.RemoveAt(indexPath.Row);
        // delete the row from the table
        tableView.DeleteRows(new NSIndexPath[] { indexPath }, UITableViewRowAnimation.Fade);
    }
}
</code></pre>

<p>Basically, <strong>DeleteTodoHandler</strong> is called whenever the user click on the <code>UISwitch</code>. It correctly deletes the cell at first. However, the indexPath is never updated.</p>

<p>By that I mean : Imagine I have 3 cells in my TodoList.</p>

<blockquote>
  <p>Cell1 -> indexPath.Row = 0
  Cell2 -> indexPath.Row = 1
  Cell3 -> indexPath.Row = 2</p>
</blockquote>

<p>If I delete the second one, Cell2, the indexPath from Cell3 should be = to 1 and not 2. This is not the case. Which means that if I try to delete Cell3 after that,</p>

<pre><code>TableItems.RemoveAt(indexPath.Row) 
</code></pre>

<p>will try to remove the item 3 from the list which is leading us to an exception since there are only 2 items in the list.</p>

<p>I'm following the examples I found in the Xamarin Doc for the deletion of rows in a TableView but in my case it's obviously not working. The indexPath.Row being read-only, what can I do guys to correctly update the indexPath after deleting an item from the TableView ?</p>