は、私は、私は、ユーザーに情報を表示するためにUIAlertCOntrollerを使用していますから抜け出すと、私は私が午前問題があるいくつかのアクションこのCatch 22の状況から抜け出す方法は?
if([NWTillHelper finishTransactionWithoutEmail] != 1) {
if([NWTillHelper getCrmId] == nil) {
//Step 1: Create a UIAlertController
UIAlertController *userInfoCheck = [UIAlertController alertControllerWithTitle:@"No Customer Email!"
message: @"Do you want to proceed without customer email? No receipt will be sent out in this case!"
preferredStyle:UIAlertControllerStyleAlert];
//Step 2: Create a UIAlertAction that can be added to the alert
UIAlertAction *Yes = [UIAlertAction
actionWithTitle:@"Yes"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
NSUserDefaults *tillUserDefaults = [NSUserDefaults standardUserDefaults];
[tillUserDefaults setInteger:1 forKey:@"finishTransactionWithoutEmail"];
[tillUserDefaults synchronize];
[userInfoCheck dismissViewControllerAnimated:YES completion:nil];
}];
UIAlertAction *No = [UIAlertAction
actionWithTitle:@"No"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
[userInfoCheck dismissViewControllerAnimated:YES completion:nil];
}];
//Step 3: Add the UIAlertAction ok that we just created to our AlertController
[userInfoCheck addAction: Yes];
[userInfoCheck addAction: No];
//Step 4: Present the alert to the user
[self presentViewController:userInfoCheck animated:YES completion:nil];
return;
}
}
を取る必要が回答に基づいてすることはできませんキャッチ22の問題が生じています完了ブロックが終了する前に最後のreturnステートメントが実行されているように見せて、ユーザーアクションで条件付きにしたい場合は、Yes alertActionにリターンを入れると、メソッドの下のコードがユーザーの前に実行されますはい/いいえを選択するチャンスがあるので、私は立ち往生しています。私は最後の復帰を実行してそのコードを停止する必要がありますが、同時に完了ブロックが完了するまで待つ必要がありますか?ユーザーがアクションを選択した後でのみ、このコードブロック全体の下にあるコードが実行されるように、この状況をどのように処理できますか?
本当に申し訳ありませんが、どのように役立ちますか?もう少し説明すればいいかもしれません –
あなたの 'self'は戻り値の後に破棄されて、それに付随するすべてのものを破壊するかもしれません。ルートビューコントローラはより永続的です。 –