相关疑难解决方法(0)

如何从UIPickerView获取选定的值

我知道使用UIDatePicker,您可以使用以下内容:

NSDate *myDate = picker.date;
Run Code Online (Sandbox Code Playgroud)

但我在我的视图中使用UIPickerView.我怎样才能同样获得选择的价值?或者我是否必须设置didSelectRow类型的方法来执行此操作?

更新:此代码适用于具有1个组件的选择器:

    NSInteger row;
    NSString *weightSelected;

    row = [repPicker selectedRowInComponent:0];
    weightSelected = [pickerArray objectAtIndex:row];
Run Code Online (Sandbox Code Playgroud)

我为这个带有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];
Run Code Online (Sandbox Code Playgroud)

cocoa-touch objective-c ios

74
推荐指数
4
解决办法
11万
查看次数

标签 统计

cocoa-touch ×1

ios ×1

objective-c ×1