1

基本的に、私がやろうとしているのは、複数の確認アラートを追加することです...しかし、それを機能させることはできません。どの確認アラートを押しても、「続行」ボタンはまったく同じもの(テキストのない本文と「XXXX」の件名)につながります...確認アラートを別のものに導く方法はありますか?

編集2; どのボタンを押しても (続行または閉じる)、アプリはユーザーを mail.app... に送信します。

        -(IBAction)mail {

                    UIAlertView *mail = [[UIAlertView alloc] init];
                        [mail setTag:ALERTVIEW_MAIL_TAG];
                        [mail setTitle:@"Open mail"];
                        [mail setMessage:@"....."];
                        [mail setDelegate:self];
                        [mail addButtonWithTitle:@"Continue"];
                        [mail addButtonWithTitle:@"Dismiss"];
                        [mail show];
                        [mail release];

                    }

                    -(IBAction)feedback {
                        UIAlertView *feedback = [[UIAlertView alloc] init];
                        [feedback setTag:ALERTVIEW_TIPSA_TAG];
                        [feedback setTitle:@"Open mail"];
                        [feedback setMessage:@"....."];
                        [feedback setDelegate:self];
                        [feedback addButtonWithTitle:@"Continue"];
                        [feedback addButtonWithTitle:@"dismiss"];
                        [feedback show];
                        [feedback release];
                    }

- (void)showConfirmAlert
                    {   
                    }   

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
                   if([alertView tag] == ALERTVIEW_FEEDBACK_TAG) {
                        NSURL *url = [[NSURL alloc] initWithString:@"mailto:?subject=XXXX"];
                        [[UIApplication sharedApplication] openURL:url];
                        [url release];
                    }

        else if (buttonIndex == 1) {
        }



           else  if ([alertView tag] == ALERTVIEW_MAIL_TAG) {
                        NSString *subject = @"YYYY";
                        NSString *body = @".....";
                        NSString *path = [NSString stringWithFormat:@"mailto:?subject=%@&body=%@", subject, body];
                        NSURL *url = [NSURL URLWithString:[path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
                        [[UIApplication sharedApplication] openURL:url];
                    }

            else if (buttonIndex == 1) {
        }

    }
4

3 に答える 3

5

オブジェクトに を設定し、デリゲート メソッドでそれらをオンにする必要がありますtagUIAlertViewこれが、デリゲート メソッドが を受け取る理由でUIAlertViewあり、ボタンが押されたオブジェクトに基づいて処理を実行できます。

#define ALERTVIEW_MAIL_TAG     100
#define ALERTVIEW_FEEDBACK_TAG 101


- (IBAction) feedback {
   UIAlertView *feedback = [[UIAlertView alloc] init];
   [feedback setTag:ALERTVIEW_FEEDBACK_TAG];
   //...
}

- (IBAction) mail {
   UIAlertView *mail = [[UIAlertView alloc] init];
   [mail setTag:ALERTVIEW_MAIL_TAG];
}

-(void) alertView:(UIAlertView *) alertView clickedButtonAtIndex:(NSInteger) buttonIndex {
  if([alertView tag] == ALERTVIEW_MAIL_TAG) {
     //do stuff...
  } else {
     //do other stuff...
  }
}
于 2011-01-11T17:37:40.757 に答える
2

デリゲート メソッドは UIAlertViewDelegate プロトコルによって指定され、変更することはできません。できることは 2 つあります。

  1. 2 つの異なるデリゲートを使用clickedButtonAtIndexし、クラスごとに -method を指定します。
  2. clickedButtonAtIndex-methodでは、最初にどのアラート ビューがメッセージを送信したかを確認します。これには、 にタグを付けるUIAlertView(Jacob Relkin による回答を参照) か、各 のインスタンス変数を作成する必要がありますUIAlertView
于 2011-01-11T17:40:15.440 に答える
0

どのボタンがキャンセル ボタンであるかを指定する必要があります。次に、どのボタンがクリックされたかを確認し、それがキャンセル ボタンである場合は何もしないでください。つまり、アラートを作成するとき:

alertView.cancelButtonIndex = 1;

そして、ボタンがクリックされたというメッセージが表示されたら:

if (buttonIndex == alertView.cancelButtonIndex) return;
于 2011-01-11T20:31:53.197 に答える