0

In was wondering whether its possible to create a button that calls a certain number (000) when pressed?

Please include everything as I am quite newb.

By everything I mean what I should put in both the header and implementation file.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
  • You appear to be asking questions which can be answered by a rudimentary search or by reading basic documentation. What have you tried so far and where are you confused? – Jonah Jul 25 '14 at 01:53
  • Well I've linked the button to the header, and added the code to the implementation file (I did this without errors). However, when I did run this on the IOS Simulator (iPhone retina 4 inch) and pressed the button, nothing would happen. I assumed it wasn't working. Until it occurred to me that this may have happened because I am using a simulator rather than a real cell phone. Help? – NerdyMoustachePanda Jul 25 '14 at 02:00
  • I think step 1 is to try not to have to guess what your software is doing. You appear to have a button on the screen. If you add a breakpoint to the method you expect it to call you can test if it is not being called or if it is not producing the result you expected. If it is not called how can you verify that the button is connected to that method? If it is called but does not behave as expected how can you god out why? – Jonah Jul 25 '14 at 02:08

1 Answers1

1

Use:

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAnimated: animated];

    UIButton *button = [UIButton buttonWithType: UIButtonTypeCustom];
    button.frame = (CGRect){100,100,100,100};
    [button addTarget: self action: @selector(makeCall:) forControlEvents: UIControlEventTouchDown];
    [self.view addSubview: button];
}

- (void)makeCall:(id)sender
{
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"tel://000]];
}
skrew
  • 879
  • 9
  • 16