0

我在表格视图单元格中有一个按钮,以及使用按钮的标题文本进行呼叫的以下操作

- (IBAction)makeCall:(id)sender
{
    UIButton *button = (UIButton *)sender;

    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString     stringWithFormat:@"tel://%@",[button titleForState:UIControlStateNormal]]]];
}

这是失败的(注意:makeCall 操作确实被调用,并且调试按钮的标题文本会给出正确的值)。

从视图上的按钮(即不在表格单元格中)使用 SAME 操作有效。

有谁知道为什么?

谢谢。

4

1 回答 1

0

您确定将方法附加到按钮上吗?

[yourButton addTarget:self selector:@selector(makeCall:) forControlEvents:UIControlEventTouchUpInside];

您始终可以使用以下方法对其进行调试NSLog

NSLog(@"Yep, it does get called, `openURL` just doesn't work ...");

在下面添加上面的行- (IBAction)makeCall:(id)sender ... {


没关系,我读到你已经确定你的方法被调用了。改为添加以下行:

NSLog(@"Yep, it does get called, `openURL` just doesn't work ...: %@", [sender title]);

如果它包含任何空格或特殊字符(基本上除了 A-Za-z0-9 之外的所有字符),您可能需要对其执行一些 URL 编码操作(或者,如果可能,将这些字符去掉)。

于 2011-08-05T12:46:30.317 回答