使用 openURL 从表格单元格中的按钮进行呼叫失败
我在表视图单元格中有一个按钮,并且使用以下操作使用按钮的标题文本进行调用
- (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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您确定已将方法附加到按钮上吗?
您始终可以使用
NSLog
进行调试:在
- (IBAction)makeCall:(id)sender ... {
下面添加上面的行没关系,我读到您已经确保你的方法被调用。添加以下行:
如果它包含任何空格或特殊字符(基本上是除 A-Za-z0-9 之外的所有字符),您可能需要对其执行一些 URL 编码操作(或者,如果可能,只删除这些字符)离开)。
Are you sure you attached your method to your button?
You can always debug it by using
NSLog
: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:
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).