tags:

views:

51

answers:

2

hello how is it possible to add a uibutton that can display a phone number and call that number automactically loading data from an array for each table view cell

thanks.

+1  A: 

The Apple docs tell you to use the tel:// url scheme. And this thread

gives a good example:

 NSString *phoneStr = [NSString stringWithFormat:@"tel:%@",[self.contactDetails objectForKey:@"phone"]];

NSString *escaped = [phoneStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:escaped]];

joelm
+1  A: 

Place a button in each cell, and set the text to the phone number from the array. Then, on the button's press selector, invoke the url tel:<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]];
}
jrtc27
thanks for this clear description however how would i add the numnbers to the array..here is my coderootArray = [[NSArray alloc] initWithObjects:@"Athens", @"Thessalonik", @"Pluto", nil]; moonArray = [[NSArray alloc] initWithObjects:@"Ath 1", @"Ath2", @"Ptolemy", nil];and what im trying to achieve is to add the button to a detailviewcontroller not to a table cell
Alex
so basically im asking how to add the phone numners to the array...thanks again
Alex
Can you clarify the structure you want please? (e.g. Having an array with lots of dictionaries etc.)
jrtc27
a phone array that would load the phones into a uibutton displayed in a detailview controller. the uibutton needs to call the number according to the array. i have a separte array for phone numners and one for data is that ok? the template im using uses uilabel to dislay this information so im not sure how to implement this thanks
Alex