【问题标题】:Having Problems Adding "Call" Button To iOS App向 iOS 应用程序添加“呼叫”按钮时遇到问题
【发布时间】:2013-06-24 15:45:50
【问题描述】:

下面是动作和警报视图。为什么当用户点击按钮时这不起作用?

警报/行动

-(IBAction)myButton
{
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"" message:@"Call (804) 378-7120?"
delegate:self cancelButtonTitle:@"NO" otherButtonTitles:@"YES",nil];
[alert show];
[alert release];
}

如何处理用户输入

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(buttonIndex==1)
{
    [[UIApplication sharedApplication]
     openURL:[NSURL URLWithString:@"tel://(804) 378-7120"]];
}
else
{
    //Do whatever you want
}
}

【问题讨论】:

  • 你的班级是否在标题中声明了UIAlertViewDelegate

标签: ios button call


【解决方案1】:

据我记得,第一个other按钮的索引是0。所以你说

if(buttonIndex==0)
      {...open you URL...}  
else
      {
        NSLog(@\"cancel\");
      }

【讨论】:

  • 由于某种原因,当用户点击按钮时,应用程序甚至没有提示警报。为什么会这样?
  • 你有没有在你的alertView:clickedButtonAtIndex:方法的if语句前设置断点来检查这个方法是否被调用过?
【解决方案2】:

根据Phone Links 的 Apple 文档,格式为:

tel:1-408-555-5555

类似于电子邮件链接,没有//,注意使用连字符,而不是括号或空格。

【讨论】:

  • 由于某种原因,当用户点击按钮时,应用程序甚至没有提示警报。为什么会这样?
  • @user2516876,确保您已将 IBAction 连接到按钮,并确保您已在标题中声明 UIAlertViewDelegate
【解决方案3】:

当用户点击 YES 选项时使用此方法。

**-(void)phoneCall {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:099123456"]];

}**

将号码 099123456 更改为您要拨打的号码。

希望这个结果有用。

【讨论】:

  • 由于某种原因,当用户点击按钮时,应用程序甚至没有提示警报。为什么会这样?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-10-11
  • 2016-03-21
相关资源
最近更新 更多