我创建了一些记录数组,并希望在选择任何单元格时设置电话设备。如8904490035
-(void)viewDidLoad {
arryAppleProducts = [[NSArray alloc] initWithObjects:@"8904490035",@"iPod",@"MacBook",@"MacBook Pro",nil];
arryAdobeSoftwares = [[NSArray alloc] initWithObjects:@"Flex",@"AIR",@"Flash",@"Photoshop",nil];
arryAdobeSoftwares1 = [[NSArray alloc] initWithObjects:@"one",@"two",@"three",@"four",nil];
self.title = @"Simple Table Exmaple";
[super viewDidLoad];
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NextViewController *nextController = [[NextViewController alloc] initWithNibName:@"NextView" bundle:nil];
[self.navigationController pushViewController:nextController animated:YES];
if(indexPath.section == 0)
[nextController changeProductText:[arryAppleProducts objectAtIndex:indexPath.row]];
else if(indexPath.section==1)
[nextController changeProductText:[arryAdobeSoftwares objectAtIndex:indexPath.row]];
else
[nextController changeProductText:[arryAdobeSoftwares1 objectAtIndex:indexPath.row]];
}
答案 0 :(得分:1)
1)从arryAppleProducts我们调用动态对象:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",[arryAppleProductsobjectAtIndex:indexPath.row]]]];
2)为了调用特定的一个arryAppleProducts,第一个对象使用以下:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",[arryAppleProducts objectAtIndex:0]]]];
根据您需要的数组对象数
替换03)如需拨打特定号码,请使用以下内容:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:8904490035"]]];
答案 1 :(得分:0)
添加像这样的方法&然后从tableViewDidSelectRowAtIndexPath
-(void)callOnMobile:(NSString *)phone {
self.phoneNumber = phone;
if(phone.length) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@", self.phoneNumber]]];
}else {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Phone Call"
message:@"Number Invalid"
delegate:self
cancelButtonTitle:@"Dismiss"
otherButtonTitles:nil, nil];
[alert show];
}
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NextViewController *nextController = [[NextViewController alloc] initWithNibName:@"NextView" bundle:nil];
[self.navigationController pushViewController:nextController animated:YES];
if(indexPath.section == 0)
[nextController changeProductText:[arryAppleProducts objectAtIndex:indexPath.row]];
[self callOnMobile:[arryAppleProducts objectAtIndex:indexPath.row]];
...
...
else if(indexPath.section==1)
[nextController changeProductText:[arryAdobeSoftwares objectAtIndex:indexPath.row]];
else
[nextController changeProductText:[arryAdobeSoftwares1 objectAtIndex:indexPath.row]];
}
这将解决你的目的。