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
 }

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

希望能帮助到你

于 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 回答