user3678641
user3678641

Reputation:

Call when clicked on tableview cell

I'm making a UITableView where you can click on a tableviewcell and this should trigger a phone call to a phone number in an array.

The phone numbers are listed in an array, and these are also shown in the tableviewcell.

_Number = @[@"100",
          @"101",
          @"070 245 245"];

I'm new at this and I don't know how to start with this, I already got my tableviewcontroller and tableviewcell classes which are working.

Gratz and thanks in advance

Upvotes: 0

Views: 89

Answers (1)

Naga Mallesh Maddali
Naga Mallesh Maddali

Reputation: 1005

You can do following :

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *phoneNumber = [Number objectAtIndex:indexPath.row];

    NSURL *phoneNumberURL = [NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",   phoneNumber]];

    if( [[UIApplication sharedApplication] canOpenURL:phoneNumberURL] )
    {
        [[UIApplication sharedApplication] openURL:phoneNumberURL];
    }
    else
    {
        UIAlertView *errorAlert = [[UIAlertView alloc] initWithTitle:@"Alert!!!" message:@"Not able to make a phone call." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
                [errorAlert show];
    }
}

Upvotes: 1

Related Questions