Textfield string to integer (to do some divisions)

Discussion in 'iOS Programming' started by Cpagal, May 22, 2010.

  1. Cpagal macrumors newbie

    Joined:
    May 22, 2010
    #1
    I have a textfield named "textField" and a label named "label".I want to add sum numbers an divide to the number i get from the "textField" and then print it on the label.

    I'm trying something like:

    int a = [textField.text integerValue];
    a = a + 2;
    label.text = a;

    But it says passing argument 1 of setText. I suppose i have to make textfield a string and then the string to integer.

    Please help!
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    textfield.text is a string and you've already converted it to an integer. The part you're missing is converting the int back to a string (for label.text).
     
  3. TiberiusXavier macrumors member

    Joined:
    Apr 18, 2010
    Location:
    Chicago
    #3
    Try building an NString:
    Code:
    label.text = [NSString stringWithFormat: @"%d", a];
    
     

Share This Page