すべての州名を配列に格納する
NSArray *states = @[@"Alabama",@"Alaska",...]
- (IBAction)button1:(id)sender
{
NSString *state = [states objectAtIndex:arc4random_uniform(states.count)];
hellolabel.text = state;
}
これにより、ランダムな州名が得られます
オーダーでご希望の場合
@interface ViewController : UIViewController
{
NSArray *_states;
}
- (void)viewDidLoad
{
[super viewDidLoad];
_states = @[@"Albama",@"Alaska"];
}
- (IBAction)button1:(id)sender
{
static NSInteger position = 0;
if(position == _states.count-1)
{
position = 0;
}
else
{
position++;
}
NSString *state = [_states objectAtIndex:position];
hellolabel.text = state;
}