Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 07-15-2011, 05:52 PM   #1 (permalink)
Registered Member
 
Join Date: Jul 2011
Posts: 13
james4026 is on a distinguished road
Question Make Phone Call from TableView cell

I've seen

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://"]];

where you are suppose to enter the number to be called. How do you get it to call a number that appears as detailTextLabel in a cell?? The detailTextLabel has been set as an NSMutableArray as has the actual TextLabel. This appears in a tableview as well.

I have only been using xcode for about 2 weeks so please be 'gentle' with me, haha.

Thanks!!
james4026 is offline   Reply With Quote
Old 07-15-2011, 06:19 PM   #2 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

Use the table delegate's tableView:didSelectRowAtIndexPath: method to find which cell was tapped and dial the associated number.
baja_yu is offline   Reply With Quote
Old 07-15-2011, 06:34 PM   #3 (permalink)
Registered Member
 
Join Date: Jul 2011
Posts: 13
james4026 is on a distinguished road
Default

Like this?

- (void)tableViewUITableView *)tableView didSelectRowAtIndexPathNSIndexPath *)indexPath {

[[UIApplication sharedApplication openURL: [NSURL URLWithString:@"tel://"];


I assume that something needs to go with "tel://" so that it knows where to get the number from?? The numbers are in an NSarray called cabNumbers if that helps.

Last edited by james4026; 07-15-2011 at 06:39 PM.
james4026 is offline   Reply With Quote
Old 07-15-2011, 07:01 PM   #4 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

You would get it from the data source where you populate the table from (most likely your array), using the indexPath parameter to get the one that was tapped.
baja_yu is offline   Reply With Quote
Old 07-15-2011, 09:54 PM   #5 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by james4026 View Post
Like this?

- (void)tableViewUITableView *)tableView didSelectRowAtIndexPathNSIndexPath *)indexPath {

[[UIApplication sharedApplication openURL: [NSURL URLWithString:@"tel://"];


I assume that something needs to go with "tel://" so that it knows where to get the number from?? The numbers are in an NSarray called cabNumbers if that helps.
Assuming your table view has a row for every entrain your cabNumbers array, you could use code like this:


Code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
  NSString* phone = [cabNumbers objectAtIndex: indexPath.row];
  NSString* urlString = [NSString stringWithFormat: @"tel://%@", phone];
  [[UIApplication sharedApplication openURL: [NSURL URLWithString: urlString];
}
The trick is the "stringWithFormat" method. It takes a format string as a parameter, and lets you combine strings with other strings, convert numbers to strings, and do various other types of format conversions. The "%@" in the format string above means "replace %@ with the contents of an object." When the object is a string, it replaces the "%@" with the contents of the string.

Do a search for "String Format Specifiers" in the XCode help system, and look for the section in the String Programming Guide titled "String Format Specifiers" for more information on using string formatting.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Reply

Bookmarks

Tags
phone call, tableview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 404
15 members and 389 guests
blasterbr, buggen, Clouds, EvilElf, HemiMG, jeroenkeij, jimmyon122, LEARN2MAKE, Mah6447, n00b, nyoe, pungs, Sami Gh, stanny, toon4413
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,667
Threads: 94,121
Posts: 402,900
Top Poster: BrianSlick (7,990)
Welcome to our newest member, host number one
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 03:52 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0