Domanda

Sono nuovo di iPhone e la programmazione Objective C, ma sono in grado di fare il mio lavoro codice. Solo che non sono sicuro se è il modo migliore per farlo, perché richiede un sacco di codice e non sembra abbastanza.

Ho una ruota UIPickerView che ha 5 componenti, 120 matrici multidimensionali (ciascuna con 13 righe e 7 colonne) che ho messo nel metodo "DidSelectRow".

Le mie due domande sono:

1) Non dovrei mettere tutte queste matrici nel metodo, ma invece imparare a metterli in un file separato, forse un database SQL? Come ho detto, il pickerView funziona bene, non è solo abbastanza codifica per uno, e forse non è lasciare che la mia corsa applicazione nel modo più efficiente possibile.

2) con tutti i componenti e gli array nella mia UIPickerView, l'unico modo sono stato in grado di ottenere i miei dati dagli array di visualizzare correttamente quando si seleziona una determinata combinazione di pickerwheels era di scrivere un sacco di "se" e " else if" dichiarazioni. Sembra ridicolo e ci deve essere un modo migliore! Non riuscivo a capire se potevo usare o il modo di utilizzare un'istruzione switch per il mio metodo. Ho incluso alcuni esempi di codice se questo aiuta chiunque a capire quello che sto cercando di fare.

Grazie per l'aiuto in anticipo!

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]];
    }
È stato utile?

Soluzione

Perché non ottimizzare il codice in qualche modo per essere come questo:

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

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

Questo è molto più pulito:)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top