Display numbers in Label with objects and loop

Discussion in 'iOS Programming' started by animefx, Jul 12, 2012.

  1. animefx macrumors regular

    Joined:
    May 10, 2005
    Location:
    Illinois
    #1
    What I'm wanting to do is take the users input in myTextView and display 1 through the number they input on myLabel. For some reason this isn't working... I'm frustrated because it's not easy assigning objects to traditional variable types like int, etc. Please don't over complicate the code if you can help me out. Thanks!

    I have this inside an action of button touch up inside btw...

    Code:
    NSString *ValueOfTextField; //object to hold myTextView.text
    
    ValueOfTextField = myTextView.text; //assigning value
    
    for (int i = 1; i <= [ValueOfTextField intValue]; i++) { 
    
    myLabel.text = myLabel.text && "@\n" && ValueOfTextField;
    
    }
     
  2. waterskier2007, Jul 12, 2012
    Last edited by a moderator: Jul 12, 2012

    waterskier2007 macrumors 68000

    waterskier2007

    Joined:
    Jun 19, 2007
    Location:
    White Lake, MI
    #2
    You should try using the NSString method stringByAppendingString

    so pretend myString is your NSString

    Code:
    myString = [myString stringByAppendingString:@"whatever_you_want_to_add"]
    give this a shot

    I would create the NSString outside of the loop, build it in the loop, and then after the loop assign it to the text property of the label
     
  3. animefx, Jul 12, 2012
    Last edited by a moderator: Jul 12, 2012

    animefx thread starter macrumors regular

    Joined:
    May 10, 2005
    Location:
    Illinois
    #3
    Thank you! This is exactly what I was looking for :)

     
  4. waterskier2007 macrumors 68000

    waterskier2007

    Joined:
    Jun 19, 2007
    Location:
    White Lake, MI
    #4
    glad I could help. Good luck
     

Share This Page