Вопрос

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