ios - UIAlertView 索引按钮

标签 ios objective-c uialertview

我的 map 上有注释代码...

//alert view

if ([ann.title isEqual: @"Al-saidiya"]) {

    NSString *msg=@"Phone No : 079011111";
    UIAlertView *alert1 = [[UIAlertView alloc]initWithTitle:@"Contact" message:msg delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:@"Call Us", nil];



    [alert1 show];
}
else if ([ann.title isEqual: @"Al-Kadmiya"]) {


    NSString *msg=@"Phone No : 07902222222";
    UIAlertView *alert2 = [[UIAlertView alloc]initWithTitle:@"Contact" message:msg delegate:self cancelButtonTitle:@"ok" otherButtonTitles:@"Call Us", nil];
    [alert2 show];
}

else if ([ann.title isEqual: @"Palestine St"]) {

    NSString *msg=@"Phone No : 0790333333";
    UIAlertView *alert3 = [[UIAlertView alloc]initWithTitle:@"Contact" message:msg delegate:self cancelButtonTitle:@"ok" otherButtonTitles: @"Call Us",nil];
    [alert3 show];
}

else if ([ann.title isEqual: @"Karada Maryam"]){

    NSString *msg=@"Phone No : 07905867";
    UIAlertView *alert4 = [[UIAlertView alloc]initWithTitle:@"Contact" message:msg delegate:self cancelButtonTitle:@"ok" otherButtonTitles:@"Call Us", nil];
    [alert4 show];
}

else if ([ann.title isEqual: @"Mansour Office"])  {

   NSString *msg=@"Phone No : 07954212";
    UIAlertView *alert5 = [[UIAlertView alloc]initWithTitle:@"Contact" message:msg delegate:self cancelButtonTitle:@"ok" otherButtonTitles: @"Call Us",nil];
    [alert5 show];
}

else if ([ann.title isEqual: @"Hunting Club"]) {


    NSString *msg=@"Phone No : 079337745";
    UIAlertView *alert6 = [[UIAlertView alloc]initWithTitle:@"Contact" message:msg delegate:self cancelButtonTitle:@"ok" otherButtonTitles: @"Call Us",nil];
    [alert6 show];
}
else if ([ann.title isEqual: @"Al-jadriya"])  {

    NSString *msg=@"Phone No : 07976231";
    UIAlertView *alert7 = [[UIAlertView alloc]initWithTitle:@"Contact" message:msg delegate:self cancelButtonTitle:@"ok" otherButtonTitles: @"Call Us",nil];
    [alert7 show];
}

else if ([ann.title isEqual: @"Al-jamea'a"]) {

    NSString *msg=@"Phone No : 07865323";
    UIAlertView *alert8 = [[UIAlertView alloc]initWithTitle:@"Contact" message:msg delegate:self cancelButtonTitle:@"ok" otherButtonTitles: @"Call Us",nil];
    [alert8 show];
}

当我应用这个方法时::

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

    if (buttonIndex==1){
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"telprompt://576576576"]]];
        NSLog(@"It works!");
    }
}

它已应用于上面的每个警报对象并采用相同的号码。我希望每个警报对象在我想打电话时都有自己的电话号码。

最佳答案

只需将标签添加到您的警报 View

if ([ann.title isEqual: @"Al-saidiya"]) {

    NSString *msg=@"Phone No : 079011111";
    UIAlertView *alert1 = [[UIAlertView alloc]initWithTitle:@"Contact" message:msg delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:@"Call Us", nil];

    alert1.tag = 0; // <--

    [alert1 show];
}

并检查 alertView:clickedButtonAtIndex: 中的标签:

if (alertView.tag == 0) {
  // call Al-saidiya
}
...

关于ios - UIAlertView 索引按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19618952/

相关文章:

ios - AppsFlyer 的 SDK 收据验证失败

iOS:XMPPFramework: 无法使用 gmail 帐户登录

ios - 从另一个类获取值后 NSInteger 保持为 null

iphone - 行动 :@selector(showAlert:) how to pass parameter in this showAlert method?

ios - 用画外音模拟 UIAlertView : making the correct sound

iOS 后台任务检测屏幕开启或关闭

ios - 我需要做什么才能在 iOS 上使用 tgmath?

iphone - 如何从 iPhone 摄像头获取实时视频流并将其发送到服务器?

objective-c - 从服务器下载本地化文件 - ios编程

ios - 在不使用 segue 的情况下单击确定警报按钮后导航到另一个 View