2013-06-24 45 views
0

下面是操作和警报视图。当用户点击按钮时为什么不能工作?遇到问题将“呼叫”按钮添加到iOS应用程序

警报/动作

-(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 
} 
} 
+0

您的类是否在头中声明了'UIAlertViewDelegate'? –

回答

0

至于我记得,第一次其他按钮的索引是0。所以你说

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

由于某些原因,应用程序甚至不会在用户点击按钮时提示警报。为什么会这样? – user2516876

+0

您是否在alertView:clickedButtonAtIndex:方法中的if语句之前设置了断点,以检查此方法是否被调用? –

0

每苹果文档Phone Links,格式为:

tel:1-408-555-5555 

到电子邮件中的链接类似,没有//,并注意使用连字符,而不是括号或空间。

+0

由于某些原因,当用户点击按钮时,应用程序甚至不会提示警报。为什么会这样? – user2516876

+0

@ user2516876,确保你将IBAction连接到了按钮上,并确保你已经在头文件中声明了'UIAlertViewDelegate'。 –

0

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

** - (无效)phoneCall {
[[UIApplication的sharedApplication]的OpenURL:[NSURL URLWithString:@ “电话:099123456”]];

} **

更改号码099123456到要叫什么数。

希望这个结果有用。

+0

由于某些原因,当用户点击按钮时,应用程序甚至不会提示警报。为什么会这样? – user2516876

+0

[alert show]被beeing调用并且alert不为null? –

相关问题