如何添加一个可显示电话号码的uibutton,并为每个表格视图单元格自动从数组中加载数据
答案 0 :(得分:1)
Apple docs告诉您使用tel:// url方案。 这thread
给出了一个很好的例子:
NSString *phoneStr = [NSString stringWithFormat:@"tel:%@",[self.contactDetails objectForKey:@"phone"]];
NSString *escaped = [phoneStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:escaped]];
答案 1 :(得分:1)
在每个单元格中放置一个按钮,并将文本设置为阵列中的电话号码。然后,在按钮的按下选择器上,调用网址tel:<PHONE NUMBER>:
- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath {
...
UIButton *callButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[callButton addTarget:self selector:@selector(callButtonPressed:)];
[callButton setTitle:@"<PHONE NUMBER>"];
[cell addSubview:callButton];
}
- (void)callButtonPressed:(id)sender {
NSString *phoneURLAsString = [NSString stringWithFormat:@"tel:%@", sender.currentTitle];
NSString *escapedPhoneURLAsString = [phoneURLAsString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:escapedPhoneURLAsString]];
}