0

如何向所有“其他”按钮添加操作?

这就是我显示警报的方式:

- (IBAction)testCalAdd:(id)sender {
    UIAlertView *alert = [[UIAlertView alloc]
    initWithTitle:@"Select week"
    message:@"Which week will you be attending?"
    delegate:self
    cancelButtonTitle:@"Cancel"
    otherButtonTitles:@"AIG Thermal $1 Million Grand Prix", @"DC VII", @"DC VI", @"DC V", @"DC IV", @"DC III", @"DC II", @"DC I", nil];
    [alert show];
}
4

2 回答 2

2

检查委托方法:

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

当您按下警报中的任何按钮时,索引会以该方法显示。

于 2013-10-30T18:10:07.037 回答
0

您可以使用 来执行此操作UIAlertViewDelegate,但使用PSAlertView更容易。

从这里的另一个答案复制。

PSAlertView *alert = [[PSAlertView alloc] initWithTitle:@"Contact"];
[alert setCancelButtonWithTitle:@"Dismiss" block:^{}];
[alert addButtonWithTitle:@"Call" block:^{
    NSString *urlString = [NSString stringWithFormat:@"telprompt://%@", phoneNumber];
    NSURL *url = [NSURL urlWithString:urlString];
    [[UIApplication sharedApplication] openURL:url];
 }];
[alert show];
于 2013-10-30T18:11:30.013 回答