美文网首页
小技巧-UISwitch

小技巧-UISwitch

作者: Jacob_LJ | 来源:发表于2018-04-19 16:08 被阅读13次
    image.png

    1

    问题:UISwitch在iOS 10中的BUG,调用setOn 或 setOn:animated:,均会再次触发action方法

    解决方法:在action中需要改变按钮状态时,将setOn方法在主队列中异步执行。

    - (IBAction)changeSwitcherStatus:(UISwitch *)sender {
        //other action ...
    
        dispatch_async(dispatch_get_main_queue(), ^{
            [sender setOn:!sender.isOn animated:YES];
        });
    }
    

    参考:http://blog.leeouf.com/2016/09/29/UISwitch%E5%9C%A8iOS%2010%E4%B8%AD%E7%9A%84BUG/
    记录日期:2018年4月19日

    相关文章

      网友评论

          本文标题:小技巧-UISwitch

          本文链接:https://www.haomeiwen.com/subject/xzbwkftx.html