I have a UI issue. Initially I wanted to have 2 pickers to populate 2 different labels. The problem is using 2 pickers on the ui will take up all the space on the window and you cannot resize the pickers.
I realized since I am using the same data in each of the pickers I should be able to get away with using one picker control. Except it will be a little confusing to the user if the focus of the control isnt done properly.
I would like for it to work kinda like the keyboard coming up in a textbox.
So I have a simple UI
Get Data 1: Textbox1 Get Data 2: Textbox2
A picker
When the user clicks inside textbox1 a picker appears instead instead of the keyboard and populates the textbox with the selected data off the picker. The same happens for text开发者_StackOverflowbox2.
Can someone give me a sample of how this maybe accomplished, or a better way to approach this? How do you guys handle having to have 2 dropdown menus on the same window?
A picker with two components and two labels (or textfields) is a good solution if your text isn't too long.
Edited to add
Here's a picker with two components that I just whipped together.
Further edited to add
Here's some code to show you how it's done:
Set up the components
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 2;
}
Set up the rows
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
if (component == 0) {
return [array1 count];
} else {
return [array2 count];
}
}
Provide data for the rows
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
if (component == 0) {
return [array1 objectAtIndex:row];
} else {
return [array2 objectAtIndex:row];
}
}
Change the labels based on changes in the picker
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
if (component == 0) {
label1.text = [array1 objectAtIndex:row];
} else {
label2.text = [array2 objectAtIndex:row];
}
}
精彩评论