5
我的應用程序是一個具有多組件拾取器轉輪的轉換器。它用於轉換一些變量。你可以看到的數字只是爲了測試,沒有什麼重要的。UIPickerView顯示錯誤的標題
- (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;
}
而且當然,告訴我是否需要顯示更多的代碼,以便了解它。它是我第一次使用這個網站btw :)