UISwitch Bool 失败? Switch isOn 不是真的
UISwitch Bool Fails? Switch isOn not True
所以我有一个奇怪的。
我目前在 App Store 中有一个清单应用程序。今天,一位用户在使用 UISwitch
.
时报告了奇怪的行为
如下所示,这是 Storyboard
中的一个简单开关,链接到 IBAction,就像我从 iOS 8.
以来一直做的那样
您选中 on
的开关,它会将图像更改为全 alpha 以表明您拥有它,否则图像将保持半透明并且 off
。
- (IBAction)Switch1:(id)sender { //IBAction linked to Switch
if([S001 isOn]) { //if Switch 'S001' is ON...
myImage.alpha = 1.0; //make image NOT transparent
...
//save ON //save data using NSUserDefaults
}
else { //else switch is OFF...
myImage.alpha = 0.3; //make image TRANSPARENT
...
//save OFF //save data using NSUserDefaults
}
}
基本上,当用户按下开关时,它会动画并更改为 ON
,但看起来 if([S001 isOn])
从未被调用,因为 if
中没有任何内容被调用。即图像不会更改为完整的 alpha 并且没有任何内容被保存为打开。
用户在 iPhone 6 运行 iOS 10.1.1
。现在奇怪的是我 运行 iOS 10.1.1 在 iPhone 7+ 上运行正常。它也适用于 iOS 9 所有屏幕尺寸。
我读了一些书,在 Whosebug 上找到了 THIS and THIS,看起来其他人也遇到了类似的问题。
所以我猜如果人们在 iOS 9 中安装了我的应用程序,然后升级到 iOS 10,那他们就会遇到这个问题,但我不能确定。因为这似乎是一个独特的案例。
这可能是什么原因造成的?我可以做些什么来为 iOS 10 个用户改进我的 IBAction?
- (IBAction)Switch1:(UISwitch *)sender { //IBAction linked to Switch
if([sender isOn]) { //if Switch 'S001' is ON...
myImage.alpha = 1.0; //make image NOT transparent
...
//save ON //save data using NSUserDefaults
}
else { //else switch is OFF...
myImage.alpha = 0.3; //make image TRANSPARENT
...
//save OFF //save data using NSUserDefaults
}
}
试试这个。这就是@rmaddy 引用发件人的意思。
为确保在切换开关时调用它,请务必在创建动作时指定 "Value Changed" 事件(通过右键单击并拖动开关到 .m 文件)
Dragging Switch from storyboard to .m
Possible Events
所以我有一个奇怪的。
我目前在 App Store 中有一个清单应用程序。今天,一位用户在使用 UISwitch
.
如下所示,这是 Storyboard
中的一个简单开关,链接到 IBAction,就像我从 iOS 8.
您选中 on
的开关,它会将图像更改为全 alpha 以表明您拥有它,否则图像将保持半透明并且 off
。
- (IBAction)Switch1:(id)sender { //IBAction linked to Switch
if([S001 isOn]) { //if Switch 'S001' is ON...
myImage.alpha = 1.0; //make image NOT transparent
...
//save ON //save data using NSUserDefaults
}
else { //else switch is OFF...
myImage.alpha = 0.3; //make image TRANSPARENT
...
//save OFF //save data using NSUserDefaults
}
}
基本上,当用户按下开关时,它会动画并更改为 ON
,但看起来 if([S001 isOn])
从未被调用,因为 if
中没有任何内容被调用。即图像不会更改为完整的 alpha 并且没有任何内容被保存为打开。
用户在 iPhone 6 运行 iOS 10.1.1
。现在奇怪的是我 运行 iOS 10.1.1 在 iPhone 7+ 上运行正常。它也适用于 iOS 9 所有屏幕尺寸。
我读了一些书,在 Whosebug 上找到了 THIS and THIS,看起来其他人也遇到了类似的问题。
所以我猜如果人们在 iOS 9 中安装了我的应用程序,然后升级到 iOS 10,那他们就会遇到这个问题,但我不能确定。因为这似乎是一个独特的案例。
这可能是什么原因造成的?我可以做些什么来为 iOS 10 个用户改进我的 IBAction?
- (IBAction)Switch1:(UISwitch *)sender { //IBAction linked to Switch
if([sender isOn]) { //if Switch 'S001' is ON...
myImage.alpha = 1.0; //make image NOT transparent
...
//save ON //save data using NSUserDefaults
}
else { //else switch is OFF...
myImage.alpha = 0.3; //make image TRANSPARENT
...
//save OFF //save data using NSUserDefaults
}
}
试试这个。这就是@rmaddy 引用发件人的意思。
为确保在切换开关时调用它,请务必在创建动作时指定 "Value Changed" 事件(通过右键单击并拖动开关到 .m 文件)
Dragging Switch from storyboard to .m
Possible Events