我的应用程序是一个带有多组件拾取轮的转换器。它用于转换一些变量。您可以看到的数字仅用于测试,实际上并不重要。
- (void)viewDidLoad
{
[super viewDidLoad];
_convertFrom = @[@"One (1)", @"Two (2)",
@"Three (3)", @"Four (4)", @"Five (5)"];
_convertRates = @[ @1.0f, @2.0f, @3.0f,
@4.0f, @5.0f];
_convertTo = @[@"One (1)", @"Two (2)",
@"Three (3)", @"Four (4)", @"Five (5)"];
_convertRates = @[ @1.0f, @2.0f, @3.0f,
@4.0f, @5.0f];
}
我在 iOS 6 模拟器中测试应用程序时显示的数字有一个小问题。正如你在这里看到的:
当我尝试从列表中删除时,数字会发生变化。但他们的价值没有。如果有人有时间检查一下并找到解决方案,那将非常有帮助:)
这是在这种情况下可能很重要的其余代码:
#pragma mark -
#pragma mark PickerView DataSource
- (NSInteger)numberOfComponentsInPickerView:
(UIPickerView *)pickerView
{
return 2;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent: (NSInteger)component
{
if (component == 0) {
return [_convertFrom count];
}
return [_convertTo count];
}
- (NSString *) pickerView: (UIPickerView *)pickerView
titleForRow:(NSInteger)row
forComponent:(NSInteger)component
{
if (component == 0) {
return [_convertFrom objectAtIndex:[pickerView selectedRowInComponent:0]];
}
return [_convertTo objectAtIndex:[pickerView selectedRowInComponent:1]];
}
#pragma mark -
#pragma mark PickerView Delegate
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row
inComponent:(NSInteger)component
{
float convertFrom = [[_convertRates objectAtIndex:[pickerView selectedRowInComponent:0]] floatValue];
float convertTo = [[_convertRates objectAtIndex:[pickerView selectedRowInComponent:1]] floatValue];
float input = [dollarText.text floatValue];
float to = convertTo;
float from = convertFrom;
float dollars = input;
float result = to * from * dollars;
float mtpaTilMtpaFloat = dollars * 1;
NSString *resultString = [[NSString alloc] initWithFormat:
@"result = %.2f * %.2f = %.2f", from, to, result];
resultLabel.text = resultString;
NSString *mtpaTilmtpa = [[NSString alloc ] initWithFormat:
@" %.2f MTPA = %.2f MTPA", dollars, mtpaTilMtpaFloat];
if (from == 1, to == 1) { resultLabel.text = mtpaTilmtpa;
}
当然,如果我需要显示更多代码以便您理解,请告诉我。这是我第一次使用这个网站顺便说一句:)