-3

I created an array of some records and want to make phone call facility when selecting any cell..like 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]];
}
creker
  • 9,280
  • 1
  • 30
  • 46

2 Answers2

1

1) For calling dynamic object from arryAppleProducts us following:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",[arryAppleProductsobjectAtIndex:indexPath.row]]]];

2) For calling on particular one no of arryAppleProducts first object use following:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",[arryAppleProducts objectAtIndex:0]]]];

replace 0 by as per your need number of object of array

3) For calling particular number use following:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:8904490035"]]];
jayraj m.g.
  • 730
  • 5
  • 18
0

add a method like this & then call it from your 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]];
}

That will solve your purpose.

Balram Tiwari
  • 5,587
  • 2
  • 22
  • 41