デリゲート関数からボタンのBGカラーを更新する必要がありますが、switch文の内部からメインスレッドにアクセスしようとすると、コンパイラエラーが発生します。SWITCHステートメントからメインのGUIスレッドにアクセスする方法は?
コードは
switch (peripheral.state) {
case CBManagerStatePoweredOn:
NSLog(@"Powered on");
[peripheral startAdvertising:_beaconPeripheralData];
dispatch_async(dispatch_get_main_queue(), ^{
_adminPageExitBtn.backgroundColor = [UIColor greenColor];
});
break;
case CBManagerStatePoweredOff:
NSLog(@"Powered Off");
[peripheral stopAdvertising];
break;
case CBManagerStateUnsupported:
NSLog(@"Device not supported");
break;
default:
break;
}
以下のよう
/Users/mdouhan/Documents/Documents - Mattias’s MacBook/NWMobileTill/NWMobileTill/AdminView.m:161:9: Cannot jump from switch statement to this case label
/Users/mdouhan/Documents/Documents - Mattias’s MacBook/NWMobileTill/NWMobileTill/AdminView.m:150:55: Jump enters lifetime of block which strongly captures a variable
を次のようにエラーメッセージがあるどのように私は正しくそのデリゲートメソッドからの私のボタンのBG色を更新していますか?
ケースを中括弧で囲みます。スコープを明示的に定義する必要がある前に問題がありました。 Ex: 'case CBManagerStatePoweredOn:{/ *ここでコードとブロック* /} break;' – Stonz2
エラーメッセージは削除されますが、ボタンは色は変わりませんが、CASEがヒットしたことを示すデバッグが表示されます –
そして、ボタンが正しく接続されていますか?メインスレッドのどこかでボタンの色を変更しようとすると、それは機能しますか? – Stonz2