UIAlertView 索引按钮 [英] UIAlertView IndexButton

查看:24
本文介绍了UIAlertView 索引按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的地图中有此代码用于注释...

I have this code right here for annotations in my 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];
}

}

当我应用这个方法时::

And when i apply this method ::

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

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

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

it has been applied on every alert objects above there and took the same number.i want every alert object to get its own phone number when i want to call.

推荐答案

首先在上面的代码中在你的警报视图中设置标签,然后在你下面的方法中.像这样尝试:-

First set the tag in your alertview in above code then in your below method. Try like this:-

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

    int indexValue=alertView.tag;

   switch (indexValue)
  {
  case 0:
    NSLog (@"zero");
   //your code
    break;
  case 1:
    NSLog (@"one");
  //your code
    break;
  case 2:
    NSLog (@"two");
  //your code
    break;
  case 3:
    NSLog (@"three");
  // your code
    break;
  case 4:
    NSLog (@"four");
  //your code
    break;
  case 5:
    NSLog (@"five");
  // your code
    break;
...... Up to

   case 8:
  // your code
   break;
  default:
    NSLog (@"done");
    break;
   }

这篇关于UIAlertView 索引按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆