Je suis novice en programmation pour iPhone et Objective C, mais je suis capable de faire fonctionner mon code. Je ne suis pas sûr que ce soit la meilleure façon de le faire, car cela demande beaucoup de code et n'est pas joli.Comment faire pour afficher ses données UIPickerView
J'ai une roue UIPickerView qui a 5 composants, 120 tableaux multidimensionnels (chacun avec 13 lignes et 7 colonnes) que j'ai placé directement dans la méthode "DidSelectRow".
Mes deux questions sont:
1) Dois-je placer pas tous ces tableaux dans la méthode, mais apprendre au lieu de les placer dans un fichier séparé, peut-être une base de données SQL? Comme je l'ai dit, le pick-up fonctionne très bien, ce n'est pas très joli, et peut-être que mon application ne fonctionne pas aussi efficacement que possible.
2) Avec tous les composants et les tableaux de mon UIPickerView, la seule façon d'obtenir mes données des tableaux pour afficher correctement quand une certaine combinaison de pickerwheels est sélectionnée était d'écrire BEAUCOUP de "si" et "else if" déclarations. Cela a l'air ridicule et il doit y avoir un meilleur moyen! Je ne pouvais pas comprendre si je pouvais utiliser ou comment utiliser une instruction Switch pour ma méthode. J'ai inclus un exemple de code si cela aide quelqu'un à comprendre ce que j'essaie de faire.
Merci pour l'aide à l'avance!
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]];
}
Wow! C'est génial merci! J'ai essayé juste ce code et tu as raison, c'est beaucoup plus propre et ça marche. Puis-je vous demander de m'expliquer un peu si vous avez le temps? Je ne comprends pas la logique et j'aimerais continuer à utiliser ce format. Merci encore! – Spottswoode
Peu importe, j'ai compris ce qui se passe maintenant ... très intelligent, merci encore! – Spottswoode
Je suis content que vous l'ayez trouvé :) J'apprécierais que vous puissiez marquer ma réponse comme une réponse acceptée, afin que je puisse obtenir quelques points :) –