I have two buttons that are not performing the IBAction that they are programmed to do. I have them correctly connected in Interface Builder, but when I click them in the simulator or on a phone, they do not perform their task. No crashes, nothing. Here is my code
MapDetailInfo.h:
@interface MapDetailInfo : UIViewController {
IBOutlet UILabel *name;
IBOutlet UITextView *address;
NSString * nameText;
NSString * addressText;
NSString * stringOne;
NSString * stringTwo;
IBOutlet UILabel *phoneNumber;
}
@property (retain, nonatomic) IBOutlet UILabel *name;
@property (retain, nonatomic) IBOutlet UITextView *address;
@property (nonatomic, copy) NSString * nameText;
@property (nonatomic, copy) NSString * addressText;
@property (retain, nonatomic) NSString * stringOne;
@property (retain, nonatomic) NSString * stringTwo;
@property (retain, nonatomic) IBOutlet UILabel *phoneNumber;
- (IBAction)callPhone:(id)sender;
- (IBAction)getDirections:(id)sender;
@end
MapDetailInfo.m:
@implementation MapDetailInfo
@synthesize name, address, nameText, addressText, phoneNumber, stringTwo, stringOne;
- (void)viewDidLoad
{
[super viewDidLoad];
NSArray *myWords = [addressText componentsSeparatedByCharactersInSet:
[NSCharacterSet characterSetWithCharactersInString:@"("]
];
stringOne = [myWords objectAtIndex:1];
stringTwo = @"(";
stringTwo = [stringTwo stringByAppendingString:stringOne];
self.name.text = nameText;
self.address.text = [myWords objectAtIndex:0];
self.phoneNumber.text = stringTwo;
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self
action:@selector(callPhone:)
forControlEvents:UIControlEventTouchUpInside];
[button setTitle:@"Call Shop" forState:UIControlStateNormal];
button.frame = CGRectMake(104.0, 332.0, 160.0, 40.0);
[self.view addSubview:button];
}
- (IBAction)callPhone:(id)sender {
NSString *URLString = [@"tel://" stringByAppendingString:stringTwo];
NSURL *URL = [NSURL URLWithString:URLString];
[[UIApplication sharedApplication] openURL:URL];
}
- (IBAction)getDirections:(id)sender {
[[UIApplication sharedApplication] openURL:
[NSURL URLWithString:[NSString stringWithFormat:@"http://maps.google.com/maps?saddr=Current Location&daddr=%@",self.address.text]]];
}
I am pulling this view from an annotation in a map. Everything works perfect accept for these two buttons not performing their task. Any help would be much appreciated. Thanks!
The reason the buttons were not working is because the URL's were incorrect. If you run into the same problem, make sure your telephone number URL's are:
@"tel://5555555"
I had the parenthesis and dash inside of mine and that is why it would not pull up. Also there was an error in my google URL.
Thanks!