简体   繁体   中英

UISwitch: what is done earlier:attached selector, or change of state?

Say, I have created an instance of UISwitch programmatically:

    UISwitch *switchBtn = [[UISwitch alloc] initWithFrame:CGRectMake(200, 10, 0, 0)];
    [switchBtn setOn:YES animated:YES];
    [switchBtn addTarget:self action:@selector(switchStateChanged:) forControlEvents:UIControlEventValueChanged];

Then, if I press that switch while application runs, what will be performed earlier: switchStateChanged, or the change of value of switchBtn.on?

For future visitors. As I found out after some obvious experimentation, in XCode 6.1.1, state of UISwitch is changed earlier than attached method is performed.

The UISwitch, when the user manipulates the switch control (“flips” it) a UIControlEventValueChanged event is generated, which results in the control (if properly configured) sending an action message.

Please find this for more details

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM