views:

90

answers:

2

Hi there.

So, I have a UISegmentedControl with:

[control addTarget:self action:@selector(myAction) forControlEvents:UIControlEventValueChanged];

Just wondering how I would find out what segment has been selected (so I can do the appropriate action). I know its something like:

@selector(myAction:) but what gets sent? ie: when I define my method what do I have to define?

Thank you.

+1  A: 
- (IBAction)myAction:(id)selector;

selector is an UISegmentedControl object. Thus you may differ two UISegmentedControl's if you bind one action to both.

kovpas
right brilliant, so - sorry to be thick ha, but what about deciding which particular segment was selected (especially as I have momentary:YES)? thanks
Thomas Clayson
+3  A: 

get the selected item... second part of question

-(IBAction) myAction:(id)sender{
    NSLog(@"myAction",nil);

    UISegmentedControl * control = sender;
    int selectedIndex = [control selectedSegmentIndex];
}
Aaron Saunders
ah brilliant... my problem was that I was trying: `int selectedIndex = [sender selectedSegmentIndex];` and not adding it to an object. :) brilliant, thank you very much.
Thomas Clayson