如何向ios警报添加操作

时间:2013-10-30 18:07:32

标签: ios objective-c uialertview

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

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

- (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];
}

2 个答案:

答案 0 :(得分:2)

检查委托方法:

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

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

答案 1 :(得分:0)

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

从另一个答案复制here

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];