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

でこれを行うことができますが、PSAlertViewUIAlertViewDelegateを使用する方がはるかに簡単です。

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];
于 2013-10-30T18:11:30.013 に答える