NSUInteger 変数 = [《UISegmentedControl》 selectedSegmentIndex];ここでは、このように処理をしています。selectedSegmentIndexは、現在選択されているセグメントのインデックス番号をNSUIntegerで返すメソッドです。また、titleForSegmentAtIndex:は、引数に指定したインデックス番号のセグメントに設定されているタイトルをNSStringで返します。これで「何番目のセグメントか」「セグメントのタイトルは何か」といった情報が取得できます。
NSString* 変数 = [《UISegmentedControl》 titleForSegmentAtIndex:番号 ];
[《UISegmentedControl》 setSelectedSegmentIndex:番号 ];また、setSelectedSegmentIndex:は、引数に指定したインデックス番号を選択します。とりあえず、この3つのメソッドがわかれば、選択されたセグメントに関する処理はできるようになるでしょう。
※リストが表示されない場合
AddBlockなどの広告ブロックツールがONになっているとリストなどが表示されない場合があります。これらのツールをOFFにしてみてください。
※MyIAppController.h #import <UIKit/UIKit.h> @interface MyIAppViewController : UIViewController { UILabel * label1; UISegmentedControl * segment1; } @property (nonatomic, retain) IBOutlet UILabel *label1; @property (nonatomic, retain) IBOutlet UISegmentedControl * segment1; - (IBAction)segment1Action:(id)sender; @end ※MyIAppController.m #import "MyIAppViewController.h" @implementation MyIAppViewController @dynamic label1; @dynamic segment1; - (IBAction)segment1Action:(id)sender { NSUInteger sgmt = [segment1 selectedSegmentIndex]; NSString* sgtl = [segment1 titleForSegmentAtIndex:sgmt]; NSString* msg = [NSString stringWithFormat: @"Segment: %i:%@",sgmt,sgtl]; [label1 setText:msg]; } ……中略…… @end
<< 前へ | 次へ >> |