使用 openURL 从表格单元格中的按钮进行呼叫失败

发布于 2024-11-28 14:42:38 字数 434 浏览 4 评论 0原文

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

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

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

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

通过视图上的按钮(即不在表格单元格中)使用相同的操作是可行的。

有人知道为什么吗?

谢谢。

I have a button in a table view cell and the following action to make a call using the title text of the button

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

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

This is failing (note: the makeCall action DOES get called, and debugging the title text of the button gives the correct value).

Using the SAME action from a button on the view (i.e. not in a table cell) works.

Anyone know why ?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

幻想少年梦 2024-12-05 14:42:38

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

[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 编码操作(或者,如果可能,只删除这些字符)离开)。

Are you sure you attached your method to your button?

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

You can always debug it by using NSLog:

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

Add the line above below - (IBAction)makeCall:(id)sender ... {


Nevermind, I read you're already sure your method gets called. Add the following line instead:

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

If it contains any spaces or special characters (basically all characters except A-Za-z0-9) you may need to perform a little URL-encoding operation on it (or, if possible, just strip those characters away).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文