Ios 导航栏中的调用按钮

Ios 导航栏中的调用按钮,ios,objective-c,nsdictionary,Ios,Objective C,Nsdictionary,拥有一个按距离排序的NSMutableArray。因此,我需要在UINavigationBar(右键)中设置一个调用按钮或标签,并使用字典和valueKey实现调用功能。我怎样才能实现它 下面是我正在使用的代码: - (void)updateViewWithDict:(NSDictionary*)dic { NSString *str = [NSString stringWithFormat:@"%@\nAddress: %@\nPhone: %@\n\nWorkTime:\n%@",

拥有一个按距离排序的
NSMutableArray
。因此,我需要在
UINavigationBar
(右键)中设置一个调用按钮或标签,并使用字典和valueKey实现调用功能。我怎样才能实现它

下面是我正在使用的代码:

- (void)updateViewWithDict:(NSDictionary*)dic {
    NSString *str = [NSString stringWithFormat:@"%@\nAddress: %@\nPhone: %@\n\nWorkTime:\n%@", [dic valueForKey:@"name"], [dic valueForKey:@"address"], [dic valueForKey:@"phone"], [dic valueForKey:@"workTime"]];

    UILabel *nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 110, 300, 140)];
    nameLabel.textAlignment = NSTextAlignmentLeft;
    nameLabel.numberOfLines = 0;
    nameLabel.text = str;
    nameLabel.textColor = [UIColor whiteColor];
    nameLabel.font = [UIFont fontWithName:@"HelveticaNeue" size:14.0];

    UIBarButtonItem *callButton = [[UIBarButtonItem alloc] initWithTitle:@"Call"
                    style:UIBarButtonItemStyleDone target:nil action:nil]; 

    self.navigationItem.rightBarButtonItem = callButton;
}
我无法获取如何将
NSURL
分配给我的按钮

我试着使用这样的代码。。但是接下来呢

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",[dic valueForKey:@"phone"]]]];
===

解决方案:-我找到了如下方法:

-(void)updateViewWithDict:(NSDictionary*)dic中,我编写了if语句

if ([[dic valueForKey:@"phone"]  isEqual: @"12345"]){

        UIBarButtonItem *callButton = [[UIBarButtonItem alloc] initWithTitle:@"Call" style:UIBarButtonItemStyleDone target:self action:@selector(FirstOffice:)];

       self.navigationItem.rightBarButtonItem = callButton;

    }

    else if ([[dic valueForKey:@"phone"]  isEqual: @"67890]){

        UIBarButtonItem *callButton2 = [[UIBarButtonItem alloc] initWithTitle:@"Call" style:UIBarButtonItemStyleDone target:self action:@selector(SecondOffice:)];

        self.navigationItem.rightBarButtonItem = callButton2;
    }
还有像这样的方法

- (void)FirstOffice:(UIBarButtonItem*)sender {
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://12345"]]];
}

- (void)SecondOffice:(UIBarButtonItem*)sender {
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://67890"]]];
}

也许还有别的办法?更简单的方法?)谢谢单击操作时使用
initWithTitle:style:target:action:
中的
target
action
参数:

UIBarButtonItem *callButton = [[UIBarButtonItem alloc] initWithTitle:@"Call" style:UIBarButtonItemStyleDone target:self action:@selector(buttonTapped)];
然后定义方法:

-(void)buttonTapped
{
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",[dic valueForKey:@"phone"]]]];
}
做这个

UIBarButtonItem *callButton = [[UIBarButtonItem alloc] initWithTitle:@"Call"
                style:UIBarButtonItemStyleDone target:self action:@selector(callSomeone:);
并添加方法

- (void)callSomeone:(UIBarButtonItem*)sender {
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",[dic objectForKey:@"phone"]]]];
}

我尝试了类似的方法,但在void中,当与字典交互时,方法[dic valueForKey…]无法识别…
-objectForKey: