문제

I have a segmented control for the user to select whether a driver is male/female.

How do i store the string "male" or "female" to a variable, dependant on what the user selects on the segmented control?

도움이 되었습니까?

해결책

If your segmented control is set up correctly to respond to the control event UIControlEventValueChanged, you can access the index of the selected segment with selectedSegmentIndex

The default value is UISegmentedControlNoSegment (no segment selected) until the user touches a segment. Once they do, calling selectedSegmentIndex: will return a NSInteger. From there you can store the string male or female depending on the index.

Example:

NSString *gender = @"unknown";
NSInteger *selectedIndex = yoursegmentcontrol.selectedSegmentIndex;
if (selectedIndex == 0)
    gender = @"male";
else 
    gender = @"female";

다른 팁

You can retrieve the index that is selected and then you have to manually correspond the index to your value.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top