给出了表格单元格内的电话

时间:2014-02-17 10:02:32

标签: ios

我创建了一些记录数组,并希望在选择任何单元格时设置电话设备。如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]];
}

2 个答案:

答案 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]]]];

根据您需要的数组对象数

替换0

3)如需拨打特定号码,请使用以下内容:

[[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]];
}

这将解决你的目的。