警报视图按钮

Pic*_*icm 1 xcode button uialertview ios xcode4.3

我正在创建一个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];

        }
Run Code Online (Sandbox Code Playgroud)

什么我想不知道我在哪里添加链接等谢谢

Oba*_*oof 11

试试以下......

UIAlertView *alert = [[UIAlertView alloc]

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

[alert show];
Run Code Online (Sandbox Code Playgroud)

然后在代码中添加以下方法:

-(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
 }
Run Code Online (Sandbox Code Playgroud)

一个建议,如果你在问题中更清楚你想要做什么,你可能会得到更多有用的答案......

希望能帮助到你