0

次のメソッド シグネチャを持つ API を使用しています。

- (BOOL)executeCommandIfConfirmed:
     (void (^)(void (^confirmationAnswer)(BOOL answer)))confirmationBlock;

誰かが正しい呼び出しがどのように見えるかの例を提供できますか? 私は苦労しています。

4

1 に答える 1

2
[object executeCommandIfConfirmed:^(void (^confirmationAnswer)(BOOL answer)) {
   confirmationAnswer(TRUE);
}];

編集:

を使用する場合はUIAlertView、通常どおりデリゲートになるクラスを作成する必要がありますが、コールバック ブロックをデリゲートのコンストラクターに渡し、それをフィールドに格納します。次に、デリゲート-alertView:didDismissWithButtonIndex:はコールバック ブロックにコールバックします。

しかし、とにかくブロックを使用している場合はPSAlertView、ブロックベースのラッパーである を使用しないでAlertViewください:

[object executeCommandIfConfirmed:^(void (^confirmationAnswer)(BOOL answer)) {
   PSAlertView *alert = [PSAlertView alertWithTitle:@"Alert" 
          message:@"Do you want to continue?"];
   [alert addButtonWithTitle:@"Yes" block:^{ confirmationAnswer(TRUE); }];
   [alert setCancelButtonWithTitle:@"No" block:^{ confirmationAnswer(FALSE); }];
   [alert show];
}];
于 2013-11-12T21:08:31.630 に答える