0

I have 2 UIButtons that change their text label with a switch statement (have only done the 1st case for testing purposes):

switch (_itemNumber)
{
    case 0:
        [_phoneButton setTitle:@"201-612-5480" forState:UIControlStateNormal];
        [_emailButton setTitle:@"aacenter@bergen.edu" forState:UIControlStateNormal];
        self.title = @"Acdmc. Adv. Center";
        break;

    default:
        break;
}

So when the UIButton is pressed an action will be performed:

- (IBAction)phoneButtonAction:(id)sender {
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",_emailButton.titleLabel.text]]];
}

- (IBAction)emailButtonAction:(id)sender {
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto://devprograms@apple.com"]];
}

Changing the text label works and, but not the action. Is it because you can only have an outlet or an action for each UIButton? If so how can I manage to perform the desired action?

Mandar Pande
  • 12,250
  • 16
  • 45
  • 72
user1330343
  • 21
  • 2
  • 7

1 Answers1

0

The mailto: and tel: URL schemes do not work on the simulator. Only the device.

Previous:

Have you added any actions to your UIButtons?

[_phoneButton addTarget:self
                 action:@selector(phoneButtonAction:)
       forControlEvents:UIControlEventTouchUpInside];
[_phoneButton addTarget:self
                 action:@selector(emailButtonAction:)
       forControlEvents:UIControlEventTouchUpInside];
Daniel Amitay
  • 6,677
  • 7
  • 36
  • 43
  • - (IBAction)phoneButtonAction:(id)sender { [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",_emailButton.titleLabel.text]]]; – user1330343 Jan 06 '13 at 20:21
  • - (IBAction)emailButtonAction:(id)sender { [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto://devprograms@apple.com"]]; – user1330343 Jan 06 '13 at 20:22
  • Are you saying that you have SET UP these actions in Interface builder? I can see that you have actions DEFINED in your code. I am asking if you have programmed your UIButtons to send these actions... – Daniel Amitay Jan 06 '13 at 20:23
  • But you are saying that these actions are not being called? – Daniel Amitay Jan 06 '13 at 20:26
  • They should, because all the connections are there, but when I run the simulator and press the any of the two buttons nothing happens. – user1330343 Jan 06 '13 at 20:27
  • The mailto: and tel: URL schemes do not work on the simulator. – Daniel Amitay Jan 06 '13 at 20:29
  • oh, ok. So you can have an outlet and an action for the same UIButton with no problems, right? – user1330343 Jan 06 '13 at 20:32
  • Yes you can. An outlet is really just an action, but managed by Interface Builder. You can have many actions on the same `UIButton`. If you place a breakpoint or an `NSLog` in either of your two outlets, you will find that they are indeed being called. – Daniel Amitay Jan 06 '13 at 20:37