如何向所有“其他”按钮添加动作?
这就是我显示警报的方式:
- (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];
}
答案 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];