我知道使用UIDatePicker,您可以使用类似以下内容的东西:
NSDate *myDate = picker.date;
但是我在视图中使用的是UIPickerView。我如何才能类似地获得所选值?还是我必须设置didSelectRow类型的方法来做到这一点?
更新:此代码适用于具有1个组件的选取器:
NSInteger row;
NSString *weightSelected;
row = [repPicker selectedRowInComponent:0];
weightSelected = [pickerArray objectAtIndex:row];
我为带有2个组件的选择器厌倦了这段代码,但它冻结了:
NSInteger row1, row2;
NSString *weightSelected1;
NSString *weightSelected2;
row1 = [repPicker selectedRowInComponent:0];
row2 = [repPicker selectedRowInComponent:1];
weightSelected1 = [pickerArray objectAtIndex:row1];
weightSelected2 = [pickerArray objectAtIndex:row2];
NSString *weightSelected = [NSString stringWithFormat:@"%@.%@", weightSelected1, weightSelected2];