0

我试图在等待事件时暂时禁用我的 UISwitch 控件。在那次事件发生后,我希望我的开关重新启用。我正在尝试使控制切换蓝牙,所以我需要等到蓝牙通电才能再次将其关闭。如果我不禁用它,我的 UISwitch 可能会与蓝牙电源不同步。顺便说一句,我正在使用 Apple 的私有框架 BluetoothManager。(我确实意识到我无法将此应用上传到 App Store,但该应用仅供个人使用。)

4

2 回答 2

0

UISwitch继承自UIControl,它有一个名为 的属性enabled。就设置这个。基本上得到与 Fry 的答案相同的结果,从你的评论中我不太确定你为什么不接受。例如:

// Presumably you're opening bluetooth using a block, so if it hasn't finished yet ...
if (!bluetooth) {
bluetoothSwitch.enabled = NO;
}

然后当初始化它的块调用蓝牙设置器时:

// If initialisation was successful re-enable
if (_bluetooth) {
bluetoothSwitch.enabled = YES
// Then just update the view containing the switch
}
于 2012-12-30T05:14:34.263 回答
0

你试过吗

mySwitch.userInteractionEnabled = NO;

?

于 2012-11-12T15:14:16.550 回答