我仍然无法使用之前的回答拨打电话。我正在解析xml文件以获取电话号码值(aMarker.phone =电话号码)。其中marker是我在解析器控制器中获取的xml文件中的属性。我可以在按钮标题上设置此电话号码字符串。但是通过点击按钮,我无法拨打该号码。看我的代码
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if(BGView.hidden == YES)
{
BGView.hidden = NO;
NSIndexPath *selectedIndexPath = [self.tableView indexPathForSelectedRow];
marker *aMarker = (marker *)[appDelegate.markers objectAtIndex:selectedIndexPath.row];
for (int selectedIndexPath = 0; selectedIndexPath < [appDelegate.markers count]; selectedIndexPath++)
{ [p_Bcard setTitle:[NSString stringWithFormat:@"%@",aMarker.phone]forState:UIControlStateNormal];
//getting correct number on p_Bcard button title.
}
}}
按钮操作代码:
-(IBAction)phonecallUpadated
{
NSIndexPath *selectedIndexPath = [self.tableView indexPathForSelectedRow];
marker *aMarker = (marker *)[appDelegate.markers objectAtIndex:selectedIndexPath.row];
for (int selectedIndexPath = 0; selectedIndexPath < [appDelegate.markers count]; selectedIndexPath++)
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",aMarker.phone]]];
//not able to call pressing p_Bcard button using above action. method get call by setting breakpoint.
我该怎么做才能传递正确的字符串号码来拨打电话。 }
答案 0 :(得分:0)
要拨打电话,您需要在tel:
附加电话号码。
它应该如下:
NSString *phone_number = @"18005551212"; // get dynamically from your code
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:%@", phone_number]]];
答案 1 :(得分:0)
首先将您的电话号码转换为UTF8编码字符串然后再制作NSURL。两个单词之间的另一个明智的设置%20(两个电话号码之间)。