Forum Xamarin.iOS

No animation when setting UISwitch.On property programatically

wellhatwellhat Member ✭✭

Hi all,

I have a custom cell with a label and a switch on the right hand side to denote whether the switch is activated or not.

I would like the switch to also be toggled if the user taps the row, rather than requiring them to actually use the switch.

I got this to work, but unlike when the user taps the switch itself, when they tap the row it does not animate the change - the switch just turns on and off with no animation at all. This doesn't look good so I need to fix it.

In my RowSelected override, I am doing this:

    var cc = (CustomCell) tableView.CellAt(indexPath);

This is the relevant code in CustomCell.cs

        private bool _enabled;
        public bool Enabled 
                return _enabled; 

                _enabled = value;
                this.CustomSwitch.On = _enabled;

        partial void CustomSwitch_ValueChanged(UISwitch sender)
            //ignore this line, it just updates my data storage

            Enabled = sender.On;

        public void ToggleSwitch()
            CustomSwitch.On = !CustomSwitch.On;

            //tried this already and it did not work
            //UIView.Animate(0.3, () => { CustomSwitch.SendActionForControlEvents(UIControlEvent.ValueChanged); });


I hope someone knows how to resolve this :)


Best Answer


  • wellhatwellhat Member ✭✭

    Thanks, that worked!

Sign In or Register to comment.