I have defined a custom cell with an UISwitch control, is the GetCell method the correct place and correct way to get the values of the cell’s control and assign it to a more persistent object than an object from the view? (GetCell method example).
if (indexPath.Section == 0)
{
switch (indexPath.Row)
{
case 0:
TVCellTwoColWBool cell = tableView.DequeueReusableCell(_cIDTwoColWBool) as TVCellTwoColWBool;
if(cell==null)
cell = new TVCellTwoColWBool("Date Filtering", MappedList.DateFilter, _cIDTwoColWBool);
cell.DataView.SWData.ValueChanged += (sender, e) => {MappedList.DateFilter = cell.DataView.SWData.On;};
return cell;
When you create or re-initialize the cell it is a good time to bind the state of any controls in the cell with the actual column/row that you want to attach the behavior to.
Your approach is correct, because it would update the values that you want. But sadly, because you are using ValueChanged as an event, you will be adding a new event handler every time the cell is dequeued.
So you would need to first remove the old event handler, and then add a new event handler. This means that you need to use a helper method for it to allow ValueChanged += FOO and ValueChanged -= FOO