0

私はiPhoneとObjectiveCプログラミングに不慣れですが、コードを機能させることができます。それが多くのコードを必要とし、きれいに見えないので、それがそれを行うための最良の方法であるかどうかはわかりません。

「DidSelectRow」メソッドに直接配置した、5つのコンポーネントと120の多次元配列(それぞれ13行7列)を持つUIPickerViewホイールがあります。

私の2つの質問は次のとおりです。

1)これらすべての配列をメソッドに配置するのではなく、別のファイル、おそらくSQLデータベースに配置する方法を学ぶ必要がありますか?私が言ったように、pickerviewは正常に機能します。これは、1つのコーディングが適切ではなく、アプリを可能な限り効率的に実行できない可能性があります。

2)UIPickerViewのすべてのコンポーネントと配列で、ピッカーホイールの特定の組み合わせが選択されたときに配列からデータを取得して適切に表示できる唯一の方法は、「if」と「elseif」を大量に書き込むことでした。ステートメント。それはばかげているように見えます、そしてより良い方法があるに違いありません!メソッドに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]];
    }
4

1 に答える 1

0

どういうわけかコードを次のように最適化してみませんか:

if (tempWheel >= 15)
    weightValue.text = [NSString stringWithFormat:@"%@",column0[tempWheel-12][runwayLengthWheel]];

else
    weightValue.text = [NSString stringWithFormat:@"%@",column0[(tempWheel-9)/2][runwayLengthWheel]];

これはずっときれいです:)

于 2010-01-08T20:24:19.360 に答える