stringWithFormat

Discussion in 'iOS Programming' started by beesbane, Oct 30, 2010.

  1. beesbane macrumors newbie

    Joined:
    Oct 16, 2010
    #1
    What is wrong with this?

    Code:
    PhoneNum.text = [[NSString alloc] initWithFormat:@"Phone:",[PhoneData valueForKey:@"number"]];
    
    I can't figure how to write it right.
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    There are no formatting placeholders in the string?
     
  3. beesbane thread starter macrumors newbie

    Joined:
    Oct 16, 2010
    #3
    Like for example...?

    Is there a better or simpler way for me to do this?
     
  4. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
  5. beesbane thread starter macrumors newbie

    Joined:
    Oct 16, 2010
    #5
    Alright, I've gotten it to work now. As long as it is set up in viewDidLoad and on a label, it works.

    How can I set it up in an IBAction?

    Code:
    -(IBAction) phoneBtn{
    	
    	NSString *phoneString = [NSString localizedStringWithFormat:@"%@  %@\n", @"tel://", [MasterData valueForKey:@"Phone"]];
    	
    	[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneString]];
    	
    }
    
     
  6. beesbane thread starter macrumors newbie

    Joined:
    Oct 16, 2010
    #6
    Oops... I feel a bit silly. I had a double space in the URL. Of course it wouldn't work.

    Writing it like this worked:

    Code:
    NSString *phoneString = [NSString localizedStringWithFormat:@"%@%@\n", @"tel://", [dvdData valueForKey:@"Phone"]];
    	[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneString]];
    
     
  7. beesbane thread starter macrumors newbie

    Joined:
    Oct 16, 2010
  8. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #8
    No worries, good to hear you've got it working. I've asked the moderators to move this to iPhone Programming. I'd suggest you might want to post future threads of a similar nature in there.
     

Share This Page