【发布时间】:2010-01-08 17:16:02
【问题描述】:
我是 iPhone 和 Objective C 编程的新手,但我能够让我的代码正常工作。我只是不确定这是否是最好的方法,因为它需要大量代码并且看起来并不漂亮。
我有一个 UIPickerView 轮,它有 5 个组件、120 个多维数组(每个数组有 13 行和 7 列),我将它们放在“DidSelectRow”方法中。
我的两个问题是:
1) 我不应该将所有这些数组都放在方法中,而是学习将它们放在单独的文件中,也许是 SQL 数据库?就像我说的那样,pickerview 工作正常,只是它的编码不太好,也许它并没有让我的应用程序尽可能高效地运行。
2)与我的UIPickerview中的所有组件和数组,我能够从阵列中获取我的数据的唯一方法,以便在选择的挑选人员的某种组合时正确显示,以写入很多“if”和“ else if”语句。看起来很可笑,一定有更好的方法!我不知道我是否可以使用或如何为我的方法使用 Switch 语句。如果这有助于任何人理解我正在尝试做什么,我已经包含了一些示例代码。
提前感谢您的帮助!
if (pressAltWheel == 0 && antiIceWheel == 0 && thrustWheel == 0)
{
{
//4600ft
if (tempWheel == 9 && runwayLengthWheel == 0)
weightValue.text = [NSString stringWithFormat:@"%@",column0[0][0]];
else if (tempWheel == 11 && runwayLengthWheel == 0)
weightValue.text = [NSString stringWithFormat:@"%@",column0[1][0]];
else if (tempWheel == 13 && runwayLengthWheel == 0)
weightValue.text = [NSString stringWithFormat:@"%@",column0[2][0]];
else if (tempWheel == 15 && runwayLengthWheel == 0)
weightValue.text = [NSString stringWithFormat:@"%@",column0[3][0]];
else if (tempWheel == 16 && runwayLengthWheel == 0)
weightValue.text = [NSString stringWithFormat:@"%@",column0[4][0]];
else if (tempWheel == 17 && runwayLengthWheel == 0)
weightValue.text = [NSString stringWithFormat:@"%@",column0[5][0]];
else if (tempWheel == 18 && runwayLengthWheel == 0)
weightValue.text = [NSString stringWithFormat:@"%@",column0[6][0]];
else if (tempWheel == 19 && runwayLengthWheel == 0)
weightValue.text = [NSString stringWithFormat:@"%@",column0[7][0]];
else if (tempWheel == 20 && runwayLengthWheel == 0)
weightValue.text = [NSString stringWithFormat:@"%@",column0[8][0]];
else if (tempWheel == 21 && runwayLengthWheel == 0)
weightValue.text = [NSString stringWithFormat:@"%@",column0[9][0]];
else if (tempWheel == 22 && runwayLengthWheel == 0)
weightValue.text = [NSString stringWithFormat:@"%@",column0[10][0]];
else if (tempWheel == 23 && runwayLengthWheel == 0)
weightValue.text = [NSString stringWithFormat:@"%@",column0[11][0]];
else if (tempWheel == 24 && runwayLengthWheel == 0)
weightValue.text = [NSString stringWithFormat:@"%@",column0[12][0]];
}
//5300ft
{
if (tempWheel == 9 && runwayLengthWheel == 1)
weightValue.text = [NSString stringWithFormat:@"%@",column0[0][1]];
else if (tempWheel == 11 && runwayLengthWheel == 1)
weightValue.text = [NSString stringWithFormat:@"%@",column0[1][1]];
else if (tempWheel == 13 && runwayLengthWheel == 1)
weightValue.text = [NSString stringWithFormat:@"%@",column0[2][1]];
else if (tempWheel == 15 && runwayLengthWheel == 1)
weightValue.text = [NSString stringWithFormat:@"%@",column0[3][1]];
else if (tempWheel == 16 && runwayLengthWheel == 1)
weightValue.text = [NSString stringWithFormat:@"%@",column0[4][1]];
else if (tempWheel == 17 && runwayLengthWheel == 1)
weightValue.text = [NSString stringWithFormat:@"%@",column0[5][1]];
else if (tempWheel == 18 && runwayLengthWheel == 1)
weightValue.text = [NSString stringWithFormat:@"%@",column0[6][1]];
else if (tempWheel == 19 && runwayLengthWheel == 1)
weightValue.text = [NSString stringWithFormat:@"%@",column0[7][1]];
else if (tempWheel == 20 && runwayLengthWheel == 1)
weightValue.text = [NSString stringWithFormat:@"%@",column0[8][1]];
else if (tempWheel == 21 && runwayLengthWheel == 1)
weightValue.text = [NSString stringWithFormat:@"%@",column0[9][1]];
else if (tempWheel == 22 && runwayLengthWheel == 1)
weightValue.text = [NSString stringWithFormat:@"%@",column0[10][1]];
else if (tempWheel == 23 && runwayLengthWheel == 1)
weightValue.text = [NSString stringWithFormat:@"%@",column0[11][1]];
else if (tempWheel == 24 && runwayLengthWheel == 1)
weightValue.text = [NSString stringWithFormat:@"%@",column0[12][1]];
}
【问题讨论】:
标签: multidimensional-array uipickerview