问题
1.--> I need to customize a UIPickerview elements to start from the top.As of now we can see the picker elements starting from the middle like the one shown in figure(apple started from middle of picker) but not from the top... Is there a way to do it?How can I do it ?
2.--> How can I make a PickerView Start At A Certain Row When It Is First Displayed I knew this code:
[self.view addSubview:aPicker];
[aPicker selectRow:14 inComponent:0 animated:NO];
But I have a textfield and I want the textfield text (eg: California) which is also one of the element of pickerView ,but its row position is not known to be displayed as the default value of UIPickerView..How can I do it ?
回答1:
1) Not sure what you mean here. Do you want the selection indicator to be at the top, and for that to be where the picker stops when you spin it? If so, I think that would be a hard thing to do.
2) To have the picker start at a particular row, just get the index of that item in the data source array, and select the picker row based on that. Something like this could be used as the text field's action method:
-(IBAction)startPickerAtText:(UITextField *) sender {
NSInteger indx = [self.theData indexOfObjectIdenticalTo:sender.text];
if (indx != NSNotFound) {
[self.picker selectRow:indx inComponent:0 animated:YES];
}
}
来源:https://stackoverflow.com/questions/13775106/customize-uipickerview-elements-to-start-at-top-in-xcode