问题描述
|
我想显示一个弹出窗口,询问用户在单击数字时是否要呼叫该数字。
我怎么做?目前,当我单击该号码时,它会自动进行呼叫。
解决方法
创建一个将委托设置为self的UIAlertView,如果selectedButtonIndex是警报中“是”按钮的buttonIndex,则拨打该号码,否则,不拨打该号码。
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@\"Title\" message:@\"Do you want to call...\" delegate:self cancelButtonTitle:@\"No\" otherButtonTitles:@\"Yes\",nil];
[alert setTag:02];
[alert show];
[alert release];
- (void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (alertView.tag == 02 && buttonIndex != alertView.cancelButtonIndex) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@\"tel://phonenumber\"]];
}
}
, 您也可以:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@\"telprompt:0123456789\"]];
获取提示,然后返回到您的应用。
, 我认为您正在寻找的是类似UIWebView自动对电话号码进行的操作。它将弹出一个UIAlertView,询问用户是否要在拨出电话之前拨打该号码。为此,使您的类为UIAlertViewDelegate并执行以下操作:
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: nil
message: phonenum
delegate: self
cancelButtonTitle:@\"Cancel\"
otherButtonTitles:@\"Call\",nil];
[alert show];
[alert release];
此外,将以下方法添加到同一类:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat: @\"tel://%@\",phoneNum]]];
}
}
当用户与其交互时,警报视图将回调该方法。 buttonIndex == 0确保仅在用户按下“呼叫”按钮时才呼叫该号码。
, 您应该使用UIAlertView方法。
该链接中提供了文档。我建议您看一下该文档,所有内容都是不言而喻的。
但是您可能需要这样的东西。
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@\"Really call?\" message:@\"Do you want to call this number?\" delegate:self cancelButtonTitle:@\"Cancel\" otherButtonTitles:nil] autorelease];
// optional - add more buttons:
[alert addButtonWithTitle:@\"Yes\"];
[alert show];