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 anyb开发者_运维问答ody seen this and have any suggestions.
I am using xcode 3.2.1 on snow leopard
thanks
==
and =
don't function the same. At a minimum you should fix that. You also don't want the added retain
to sender.
精彩评论