UISegemnted COntrol - selecting 3rd segment activates second segment

Posted by diggers25 on Stack Overflow See other posts from Stack Overflow or by diggers25
Published on 2010-04-11T17:18:22Z Indexed on 2010/04/11 17:23 UTC
Read the original article Hit count: 258

Filed under:

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

© Stack Overflow or respective owner

Related posts about controls