UISegmentedControlは数個の選択肢から排他的に選択する場合に有効だそうです。
参考にさせて頂いたサイト。
Objective-C Segmented(セグメント) – iscene ページ!
ゲームのLevel、難易度に使用しました。
#import "ViewController.h" @interface ViewController ()//<UIAlertViewDelegate> { int level;//Levelの設定 } - (IBAction)levelChange:(UISegmentedControl *)sender; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. //レベルの初期値 level = 10; } #pragma mark - レベルの設定 - (IBAction)levelChange:(UISegmentedControl *)sender { switch (sender.selectedSegmentIndex) { case 0: level = 10; _recordHyouji.text = [NSString stringWithFormat:@"%04d",recordCount];//それぞれ表示 _timeHyouji.text = [NSString stringWithFormat:@"%05.2f",10.00]; break; case 1: level = 30; _recordHyouji.text = [NSString stringWithFormat:@"%04d",recordCount30];// _timeHyouji.text = [NSString stringWithFormat:@"%05.2f",30.00]; break; case 2: level = 60; _recordHyouji.text = [NSString stringWithFormat:@"%04d",recordCount60];// _timeHyouji.text = [NSString stringWithFormat:@"%05.2f",60.00]; break; } }
ボタンを選択すると、選択した番号を持ってaction接続したメソッドへ飛びます。
そこでswitch文でそれぞれにあった動作をさせます。