I have a UIPickerView
combined with a UITextField
that allows users to select their gender when signing up for an account. The text field has a placeholder that says "gender" to indicate what that particular text field is for. The issue I am running into is that when the user clicks on the gender bar, the picker shows the first option as being selected (in my case, "male").
I have implemented the didSelectRow
delegate that updates the text fields value when a picker row is selected; however, the loading of the picker view does not trigger a selection. meaning if a user wants to select male, they have to scroll to female, then back to male to trigger the selection. Is there a way that when the picker view loads I immediately am able to catch that event and load the first available selection from my picker view?
Is there a better option for showing 2 option selections? The UISegmentedControl
feels a bit out of place with the rest of the UI on that page.
- (NSInteger)numberOfComponentsInPickerView:
(UIPickerView *)pickerView
{
return 1;
}
// The number of rows of data
- (NSInteger)pickerView:(UIPickerView *)pickerView
numberOfRowsInComponent:(NSInteger)component
{
return self.genderData.count;
}
// The data to return for the row and component (column) that's being passed in
- (NSString*)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent: (NSInteger)component
{
return self.genderData[row];
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
self.genderField.text = self.genderData[row];
}