我想爲某些單位的東西做一個簡單的轉換器,我似乎無法管理從兩列中獲取數據,並將它們變成我可以計算的變量。我也收到一些錯誤,如果有人願意,我會很感激。錯誤出現在#pragma標記 - PickerView委託中,我認爲我的代碼中有90%是錯誤的。UIPickerView與兩行
這裏是完整的.h文件。 (希望我這次以正確的方式做到這一點) 如果有人有時間研究它,這裏是完整的項目。 http://www.mediafire.com/download.php?ss706o783ioa59u
#import "MainViewController.h"
@interface MainViewController()
@end
@implementation MainViewController
@synthesize _convertFrom, _convertTo, _convertRates;
@synthesize dollarText, picker, resultLabel;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
_convertFrom = @[@"Australia (AUD)", @"China (CNY)",
@"France (EUR)", @"Great Britain (GBP)", @"Japan (JPY)"];
_convertRates = @[ @0.9922f, @6.5938f, @0.7270f,
@0.6206f, @81.57f];
_convertTo = @[@"Australia (AUD)", @"China (CNY)",
@"France (EUR)", @"Great Britain (GBP)", @"Japan (JPY)"];
_convertRates = @[ @0.9922f, @6.5938f, @0.7270f,
@0.6206f, @81.57f];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
//dont forget to put something in here later
}
- (IBAction)textFieldReturn:(id)sender {
[sender resignFirstResponder];
}
#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 from = [[_convertRates objectAtIndex:[pickerView selectedRowInComponent:0] floatValue]];
float to = [[_convertRates objectAtIndex:[pickerView selectedRowInComponent:1] floatValue]];
float input = [dollarText.text floatValue];
// This stuff is from some guide.
//float rate = [_convertRates[row] floatValue];
//float dollars = [dollarText.text floatValue];
//float result = dollars * rate;
NSString *resultString = [[NSString alloc] initWithFormat:
@"%.2f @% = %.2f %@", input, [[_convertRates objectAtIndex:[pickerView selectedRowInComponent:0] floatValue]], result, [[_convertRates objectAtIndex:[pickerView selectedRowInComponent:0] floatValue]]];
resultLabel.text = resultString;
}
#pragma mark - Flipside View
- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller
{
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"showAlternate"]) {
[[segue destinationViewController] setDelegate:self];
}
}
@end
感謝提前:)
有什麼錯誤?不要讓我們猜測。 :)他們是編譯錯誤還是運行時錯誤?清楚地表明確切的錯誤以及它與哪一行相關聯。 – rmaddy
對不起,編譯器錯誤。幾乎每一個生活在pragma pickerview委託之外。他們大多數是「失蹤」;「」,編譯錯誤。 –