2012-11-08 56 views
0

我試圖在等待事件時暫時禁用我的UISwitch控件。事件發生後,我希望我的開關重新啓用。我試圖讓控制切換藍牙,所以我需要等到藍牙通電才能再次關閉它。如果我不禁用它,那麼很可能我的UISwitch將會與藍牙電源失去同步。順便說一句,我正在使用蘋果的私人框架,BluetoothManager。 (我知道我不能上傳這個應用程序在App Store,但應用程序的供個人使用。)如何在等待事件時暫時禁用UISwitch?

回答

0

你試過用

mySwitch.userInteractionEnabled = NO; 

+0

不完全是,我想爲它等待,甚至爲它變成啓用。不是即時的,但謝謝你給它一個鏡頭。 – MPX

0

UISwitch繼承自UIControl,它有一個名爲enabled的屬性。只需設置此。基本上和弗萊的答案有同樣的結果,我不太清楚你的評論爲什麼你不接受。例如:

// 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 
}