UISegemnted COntrol - selecting 3rd segment activates second segment

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

Answers


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


Need Your Help

Zend Form decorators trouble

zend-framework zend-form decorator

How do I achieve the following with form decorators for form elements:

VB Access DB Update statement

sql database vb.net

I am new to this forum, please could you help me get this code to work, when i execute it, it simply does nothing and does not update the DB. If i remove the square brackets it gives an error: "SYN...