0

I am creating a dialpad application in Xcode (which is very similar to the iPhone Phone app) and everything is working but the buttons linking up to the label.

What would be the code to add a certain number onto the end of other numbers on a label (if that makes sense!)? The number would be based on what title the label has (so that it will automatically work out if the button is number 6 or number 2 etc...).

The label which I need the numbers in is called phoneNumberLabel.

Here's the code I'm using (which won't work);

-(void)displayPhoneNumber
{
self.phoneNumberLabel.text = self.phoneNumberString;  

NSLog(@"Displayed Phone Number");
}

-(IBAction)numberButtonPressed:(UIButton *)pressedButton
{
int toneIndex = [pressedButton.titleLabel.text intValue];
SystemSoundID toneSSID = toneSSIDs[toneIndex];
AudioServicesPlaySystemSound(toneSSID);

self.phoneNumberString = [self.phoneNumberString stringByAppendingString:pressedButton.titleLabel.text];
[self displayPhoneNumber];

NSLog(@"Number Pressed");
}
NSGod
  • 22,699
  • 3
  • 58
  • 66
pixelbitlabs
  • 1,934
  • 6
  • 36
  • 65

1 Answers1

0

You should try:

NSMutableArray *pressedNumbers = [NSMutableArray alloc];
[pressedNumbers addObject:self.phoneNumberLabel.text];
    //THEN
NSMutableString *numberComplete = [NSMutableString alloc];
for (NSString *temp in pressedNumbers) {
    [numberComplete appendString:temp];
}

If I understand what you want to do

Nicolò Ciraci
  • 678
  • 5
  • 23
  • Hi, yes but wouldn't it need to get the button title in order to work out which number to add to the label, like in my code above? :-) – pixelbitlabs Aug 10 '11 at 17:43
  • P.S. It didn't work anyway, an NS error appeared when I tapped on a button :-( – pixelbitlabs Aug 10 '11 at 17:47
  • Uhm, do you have 10 button? One for each number? – Nicolò Ciraci Aug 10 '11 at 18:23
  • Indeed, they all have button titles (e.g. 1, 2, 3..). See my current code for reference (above). – pixelbitlabs Aug 10 '11 at 18:26
  • I've got the solution, look that (Pastie.org is cool ;) ) [link]http://pastie.org/private/q2md5vkbi5oaktotoeew – Nicolò Ciraci Aug 10 '11 at 18:58
  • Great thanks! Where would I put the first lines of code which you've shown Pastie? :-) – pixelbitlabs Aug 10 '11 at 19:01
  • I've been trying to add your code in, but I don't think you understand fully what I wanted. It's kind of making it too complicated. Do you have an alternative method or a solution as to why my current code (above) isn't working? Thanks for your help! :-) – pixelbitlabs Aug 10 '11 at 19:38
  • The code that I have wrote allow you to understand what button you pressed. Tell me what you wanna do ;) – Nicolò Ciraci Aug 10 '11 at 19:47
  • No, the main thing is that I need to add a number onto the end of a label - so say the label text is "486563" and then I press the "5" button, it will then add 5 onto the end of that number, producing "4865635"... :-) – pixelbitlabs Aug 11 '11 at 06:51
  • But then how would it add the number onto the end of the existing label? It pulls up an error anyhow when I did what you said... http://pastie.org/2362452 – pixelbitlabs Aug 12 '11 at 18:34
  • I hope that works for you. I wrote that at 1.30 AM ç.ç After a birthday party for 18 years [link]http://cl.ly/0P3W1a1i042A3v1e1p3y – Nicolò Ciraci Aug 12 '11 at 23:41
  • Awesome thanks very much! You wouldn't possibly be able to help with this would you?: http://stackoverflow.com/questions/7058872/xcode-how-would-i-dial-a-number-and-then-key-in-numbers-to-the-dialpad-five-seco :) – pixelbitlabs Aug 14 '11 at 18:58
  • Ah, come across an issue. I've added a "Dial" button which would use the label to call the phone number. Here's the code I used: http://pastie.org/2371646. The phone application opens as expected but it calls 6855 instead of the number on the label. What am I doing wrong? – pixelbitlabs Aug 14 '11 at 19:10
  • Why do you use a string like this:@"tel:01613542800,,,,,,,,,%@" ??? Try with @"tel:%@" – Nicolò Ciraci Aug 17 '11 at 21:42