UIPickerView 中的隐藏值

Hidden Values in UIPickerView

作为 iOS 开发的初学者,我在 UIPickerView 的具体实施方面遇到了困难。 我已经知道如何使用特定数据创建UIPickerView

虽然我的目标有点复杂 - 我希望这个 PickerView 打印我选择的值。例如 - 就像在简单的货币计算器中一样 - 我选择欧元货币并且打印出值“4.30”。

仅供参考 - 我需要将此值传递给另一个 ViewController 以便相乘。 任何帮助将不胜感激!

这是示例代码 - 现在我仍在尝试了解我应该在这里做什么

@interface SecondViewController ()

{
    NSArray *currency;
}
@property NSArray *currency;

@end

@implementation SecondViewController
@synthesize currencyValue;
@synthesize currency;
- (IBAction)Back:(id)sender {
    [self dismissViewControllerAnimated:NO completion:NULL];

}

- (NSInteger) numberOfComponentsInPickerView:(UIPickerView *)pickerView {
    return 1;

}

- (NSInteger) pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {

    return [self.currency count];
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:
            (NSInteger)component {
    return self.currency[row];

     }

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
    [currencyValue setText:[NSString stringWithFormat:@"Exchange rate of currency : %@",[currency objectAtIndex:row]]];

}


-(IBAction)currencyValue:(id)sender {



}

- (void)viewDidLoad {
    [super viewDidLoad];

    self.currency = @[@"EUR", @"PLN", @"CFH", @"DKK", @"SEK", @"NOK"];

UIPickerViewDelegate 中,您可以将带有 pickerView:titleForRow:forComponent: 的行的标题设置为文档中的 described

UIPickerViewselectedRowInComponent: will return 您当前选定的行:使用具有此索引的先前数据源来检索当前选定的标题。