简体   繁体   English

UISwitch未返回其当前状态(开/关)

[英]UISwitch not returning its current state (on/off)

Here is the IBAction method linked to the UISwitch with the valueChanged event : 以下是使用valueChanged事件链接到UISwitch的IBAction方法:

- (IBAction) sanitySwitch {
if (checkoption.on == YES) {
    NSLog(@"SanityCheck ENABLED");
    sanityCheck = YES;
} else {
    NSLog(@"SanityCheck DISABLED");
    sanityCheck = NO;
}
}

It always returns "SanityCheck DISABLED". 它总是返回“SanityCheck DISABLED”。 The UISwitch checkoption is correcty linked to its object from the XIB file and proper @propery and @syntetize setting have been placed. UISwitch checkoption正确地链接到XIB文件中的对象,并且已经放置了正确的@propery和@syntetize设置。

Replace the code with the this code. 用此代码替换代码。 and connect again with switch as value change control event. 并再次与switch连接作为值更改控制事件。

- (IBAction) sanitySwitch:(id)sender {
    if ([sender isOn]) {
        NSLog(@"SanityCheck ENABLED");
        sanityCheck = YES;
    } 
    else {
        NSLog(@"SanityCheck DISABLED");
        sanityCheck = NO;
    }
}

You are using property "on" wrong way You have to check as follows: 您正在使用属性“打开”错误的方式您必须检查如下:

if ([checkoption isOn])

See the documentation properly. 请正确查看文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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