こんにちは、こんにちは。私はここでいくつかの問題を抱えています。正直に言うと、同じ画面に異なるメッセージで異なるアラートビューを作成する必要があることを理解していません。これらのアラートのほとんどにはボタンが 1 つしかありませんが、これがあります2つのボタンが必要な削除するには、他のボタンは1つしかないため、2つのボタンのスクリーンビューを作成し、 (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex メソッドを追加すると、いくつかの問題があります
ここにいくつかのコード
- (IBAction)saveInfo{
if (med.text.length ==0) {
UIAlertView *alertViewError = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"ERROR",@"")
message:NSLocalizedString(@"EMPTY1",@"")
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
[alertViewError show];
[alertViewError release];
}
else if(medicamento.text.length >= 41){
[self lenghtError:40:NSLocalizedString(@"TF_MED",@"")];
}
else if (med.text.length ==0 || descripcion.text.length == 0) {
UIAlertView *alertViewError = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"ERROR",@"")
message:NSLocalizedString(@"EMPTY2",@"")
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
[alertViewError show];
[alertViewError release];
}
else if (descripcion.text.length >= 41){
[self lenghtError:40:NSLocalizedString(@"TF_DESCRIPCION",@"")];
}
else{
[self insertDictionary];
UIAlertView *alertViewAcept = [[UIAlertView alloc] initWithTitle:@""
message: NSLocalizedString(@"ACCEPT_MSG",@"")
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
[alertViewAcept show];
[alertViewAcept release];
[self.navigationController popViewControllerAnimated:YES];
}
}
- (IBAction)cancelData{
UIAlertView *alertViewCancel =
[[UIAlertView alloc] initWithTitle: NSLocalizedString(@"BT_DELETE_MED",@"")
message: NSLocalizedString(@"MSG_DELETE_MED",@"")
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles: @"Cancel", nil];
[alertViewCancel setTag:999];
[alertViewCancel show];
[alertViewCancel release];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (alertView.tag == 999) {
if(buttonIndex==0){
[self.Bayer_DB_obj deleteRowWithKeyValue:[NSString stringWithFormat:@"%d",IdMed] onKeyName:@"id_ctl_med" onTable:@"ctl_med"];
// code to delete here
[self.navigationController popViewControllerAnimated:YES];
}
}
}
そのため、最初の部分では、ユーザーが間違いを犯していることを示すアラートをいくつか作成しました。2 番目の部分では、削除する前に確認が必要ですが、ここでは 2 つのボタンが必要であり、3 番目の部分では、呼び出されたメソッドがあります。アラートにタグを追加して、すべてのアラートでこの比較を行わないようにしました。問題は、alertViewAcept を表示すると、前のビュー コントローラーに移動し、クリックした後に[OK] ボタン (実際には cancelbuttontitle です) アプリは「エラー メッセージ」なしでクラッシュします
何が間違っているのかわからないので、助けてください