次のメソッド シグネチャを持つ API を使用しています。
- (BOOL)executeCommandIfConfirmed:
(void (^)(void (^confirmationAnswer)(BOOL answer)))confirmationBlock;
誰かが正しい呼び出しがどのように見えるかの例を提供できますか? 私は苦労しています。
次のメソッド シグネチャを持つ API を使用しています。
- (BOOL)executeCommandIfConfirmed:
(void (^)(void (^confirmationAnswer)(BOOL answer)))confirmationBlock;
誰かが正しい呼び出しがどのように見えるかの例を提供できますか? 私は苦労しています。
[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];
}];