The following code adds a call button to the application and click it to call the phone number. It is useful for iPhone developers.
// Add the phone icon button
UIButton * btnPhone = [[UIButton buttonWithType: UIButtonTypeCustom] retain];
BtnPhone. frame = CGRectMake (280,10, 30,30 );
UIImage * image = [UIImage imageNamed: @ "phone.png"];
[BtnPhone setBackgroundImage: image forState: UIControlStateNormal];
// Click the dialing button to directly dial
[BtnPhone addTarget: self action: @ selector (callAction: event :) forControlEvents: UIControlEventTouchUpInside];
[Cell. contentView addSubview: btnPhone]; // cell is a UITableViewCell
// Define the operation when the dial button is clicked
-(Void) callAction :( id) sender event :( id) event {
NSSet * touches = [event allTouches];
UITouch * touch = [touches anyObject];
CGPoint currentTouchPosition = [touch locationInView: self. listTable];
NSIndexPath * indexPath = [self. listTable indexPathForRowAtPoint: currentTouchPosition];
If (indexPath = nil ){
Return;
}
NSInteger section = [indexPath section];
NSUInteger row = [indexPath row];
NSDictionary * rowData = [datas objectAtIndex: row];
NSString * num = [[NSString alloc] initWithFormat: @ "tel: // % @", number]; // number indicates the number string
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: num]; // dial
}