tags:

views:

33

answers:

1

I have a segmented control with 3 defined segments. i am looking to capture the segment index so I can use it in an if statement to update variables accordingly as such:

-(IBAction)numPlayers:(id)sender; { numPlayersSegment = [(UISegmentedControl *)sender retain]; if (numPlayersSegment.selectedSegmentIndex == 0) { numOfPlayers = 2; } else if (numPlayersSegment.selectedSegmentIndex = 1) { numOfPlayers = 3; } else if (numPlayersSegment.selectedSegmentIndex = 2) { numOfPlayers = 4; } else if (numPlayersSegment.selectedSegmentIndex = -1) { numOfPlayers = 0; }

NSLog(@"Players selected = %d", numPlayersSegment.selectedSegmentIndex);

However whenever I press the third segment (index 2) it returns the value of the second segment (index 1) and also highlights the 2nd segment. I can see nothing untoward in IB.

Has anybody seen this and have any suggestions.

I am using xcode 3.2.1 on snow leopard

thanks

A: 

== and = don't function the same. At a minimum you should fix that. You also don't want the added retain to sender.

Paul Lynch