#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    1
    Rep Power
    0

    How can I continue this if statement?


    I am trying to make an app that for each time you press the button a new US state comes up, like first press Alabama and the second press Alaska and so on, but I don't know how to continue. Here is the code I have produced this far:

    - (IBAction)button1: (id)sender {

    if([hellolabel.text isEqualToString:@"Alabama"])
    {

    hellolabel.text = @"Alaska";

    }

    else

    {

    hellolabel.text = @"Alabama";

    }

    }
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Location
    India
    Posts
    95
    Rep Power
    4
    posted in multiple places
    Here

    Here

    and also posted in wrong forum.
  4. #3
  5. Contributing User

    Join Date
    Aug 2003
    Location
    UK
    Posts
    5,114
    Rep Power
    1803
    Originally Posted by eramit2010
    and also posted in wrong forum.
    Not at all, check the description of this forum:

    C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C.
    I am pretty sure whoever wrote the description meant "Objective-C" not "Object-C".

    That said there are few Objective-C experts around here, so perhaps not a well chosen forum, but certainly not "wrong".
  6. #4
  7. Contributing User

    Join Date
    Aug 2003
    Location
    UK
    Posts
    5,114
    Rep Power
    1803
    I am no Objective-C expert, but I would suggest you are making a simple problem over-complex.

    All you need is an array of strings in the order you wish them to appear, and an incrementing counter to index the array.

    Using plain C code as a pseudo-code that I am sure you can adapt to Objective-C and the GUI API you appear to be targeting:
    Code:
    static const char* data[]
    {
        "Alabama", "Alaska", ..., NULL ;
    } ;
    
    void button_handler()
    {
        static int index = 0 ;
    
        settext( data[index] ) ;
        index++ ;
    
        if( data[index] == NULL )
        {
            index = 0 ;
        }
    }

IMN logo majestic logo threadwatch logo seochat tools logo