-1

全て:

i) タイトルが Count のボタンを無効にしようとしています ii) そのタイトルを Busy に変更し、デルタ秒の遅延の後 iii) ボタンを有効にして iv) そのタイトルを Count に戻します

これはすべて、UIButton のアクションのコードで発生するはずです。

手順 i) から iii) は実行できますが、手順 iv) は機能しません。

[sender setEnabled:NO];  // the button is now disabled, clicking on it has no effect 
[sender setTitle:@"Busy ... " forState:UIControlStateDisabled];


// wait delay seconds before reenabling the count button
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, delta * NSEC_PER_SEC),
               dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),^{
               [self.countBTN setEnabled:YES];
               [self.countBTN setTitle:@"Count" forState:UIControlStateReserved];
               });

// after delta seconds, the button is re-enabled, but its title is still "Busy ..."

これが機能しない理由についての洞察をいただければ幸いです。

4

1 に答える 1

4

バックグラウンド スレッドではなく、メイン スレッドで UI コードを実行する必要があります。

変化する:

dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)

に:

dispatch_get_main_queue()

編集:

ボタンのメイン タイトルを変更UIControlStateReservedする場合は、に変更する必要がある場合もあります。UIControlStateNormal

于 2013-07-19T00:44:31.783 に答える