1

iOS アプリケーションを作成しています。スコアが 100 に達すると、このアラートが表示され、ボタン (共有、アップル、このアプリの評価) 以外はすべて正常に機能します。

     - (void) buttonAction {
                counter++;
                if(counter == 100)
                    [self showAlert];
            }

            - (void) showAlert {

                UIAlertView *alert = [[UIAlertView alloc]

                                      initWithTitle:@"hello"
                                      message:@"whats you name" 
                                      delegate:nil 
                                      cancelButtonTitle:@"Dismiss" 
                                      otherButtonTitles:@"share", @"apple" , @"rate this app", nil]; 


 -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
        if (buttonIndex == 0) { // means share button pressed
            // write your code here to do whatever you want to do once the share button is pressed
        }
        if(buttonIndex == 1) { // means apple button pressed
            // write your code here to do whatever you want to do once the apple button is pressed
        }
        // and so on for the last button
    }

                [alert show];



            }

            -(IBAction)plus {
                counter=counter + 1;
                count.text = [NSString stringWithFormat:@"%i",counter];
                if(counter == 100)
                    [self showAlert];

            }

            -(IBAction)zero {
                counter=0;
                count.text = [NSString stringWithFormat:@"%i",counter];
            }



        - (void)viewDidLoad {
            counter=0;
            count.text = @"0";
                [super viewDidLoad];

        }

私がしたいことはどこにリンクなどを追加すればよいですか。ありがとうございます

4

3 に答える 3

11

次のことを試してください...

UIAlertView *alert = [[UIAlertView alloc]

                      initWithTitle:@"hello"
                      message:@"whats you name" 
                      delegate:self 
                      cancelButtonTitle:@"Dismiss" 
                      otherButtonTitles:@"share", @"apple" , @"rate this app", nil]; 

[alert show];

次に、コードに次のメソッドを追加します。

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
      if (buttonIndex == 0) { // means share button pressed
              // write your code here to do whatever you want to do once the share button is pressed
      }
      if(buttonIndex == 1) { // means apple button pressed
              // write your code here to do whatever you want to do once the apple button is pressed
      }
      // and so on for the last button
 }

1つのアドバイスとして、質問で正確に何をしたいのかをより明確にすると、より役立つ回答が得られる可能性があります...

それが役に立てば幸い

于 2012-07-14T12:22:21.353 に答える
0

あなたの質問から、ユーザーがどのアラートボタンが押されたかを識別する方法が必要だと理解しています。そのためには、次のデリゲートメソッドを使用できます。

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{

}

このメソッド内では、ユーザーが押したボタンのインデックスを確認する必要があります。そしてそれによると、あなたは他のことをすることができます。

delegateデリゲートメソッドを使用するには、アラートビューのをに設定する必要がありますself

詳細については、http: //developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIAlertView_Class/UIAlertView/UIAlertView.htmlを参照してください。

http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIAlertViewDelegate_Protocol/UIAlertViewDelegate/UIAlertViewDelegate.html#//apple_ref/doc/uid/TP40007548

于 2012-07-14T12:22:31.527 に答える
0

UIAlertViewDelegateメソッドを実装する必要があり– alertView:didDismissWithButtonIndex: ます。コントローラーを初期化するときにUIAlertViewDelegateとして設定し、の実装内で– alertView:didDismissWithButtonIndex:、関連するボタンインデックスに関連するさまざまなメソッドを呼び出します。

于 2012-07-14T12:22:36.153 に答える