Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIPickerView programmatic example?

How do I programmatically setup up the UIPickerView in a view without using Interface Builder? Also having trouble understanding how to work with the delegate portions of the UIPickerView.

like image 884
Kristen Martinson Avatar asked Jul 09 '11 17:07

Kristen Martinson


People also ask

What is UIPickerView in Swift?

A view that uses a spinning-wheel or slot-machine metaphor to show one or more sets of values.

How do you create a picker in Swift?

You create a picker by providing a selection binding, a label, and the content for the picker to display. Set the selection parameter to a bound property that provides the value to display as the current selection.


1 Answers

To add UIPickerView programmatically:

- (void)pickerView:(UIPickerView *)pV didSelectRow:(NSInteger)row inComponent:(NSInteger)component {     if(component == 1)         selectedRowPicker1 = row;     else if(component == 2)         selectedRowPicker2 = row;     else         selectedRowPicker3 = row; }  - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {     return 3; }  - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {      if(component == 1)         return [list1 count];     else if(component == 2)         return [list2 count];     else         return [list3 count]; }  - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {     if(component == 1)         val1 = [list1 objectAtIndex:row];     else if(component == 2)         val2 = [list2 objectAtIndex:row];     else         val3 = [list3 objectAtIndex:row];      return strTemp; } 
like image 126
AppAspect Avatar answered Sep 20 '22 09:09

AppAspect