特定の状況が発生したかどうかに応じて異なるメッセージを表示するalertViewを表示したいアプリケーションを作成しています。いずれの状況も一致しない場合は、アラートを表示せず、残りのアプリケーションを処理する必要があります。私の問題は、これを行う方法がわからないことです。私は次のコードを持っています:
- (void) methodThatIsCalled {
NSString *msg;
if (blah) {
msg = @"Message A";
}
else if (blah blah) {
msg = @"Message B";
}
else if (blah blah blah) {
msg = @"Message C";
}
//Here is where I want to display the Alert code
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
message:msg
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
else {
Do rest of the application....
}
}
アラートを表示するコードのブロックが1つだけで、メッセージ文字列をアラートに動的に渡し、どの句も一致しない場合は何もしないように、これを行う方法を誰かに教えてもらえますか?
返信してくださった皆様、ありがとうございました。