作为iOS的初学者,我正在努力实现UIPickerView
的具体实现。 我已经知道如何用特定数据创建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"];
随意附上代码示例以获取更详细的答案。 – iOSdev