これは、整数が一定量以下の場合、ビューコントローラのボタンを無効にするコードです。私は整数のエラー
plancnt.set(20, forKey: "plancnt")
plancnt.synchronize()
を書くとき
if (plancnt.value(forKey: "plancnt") != nil){
plancnt.set(1, forKey: "plancnt")
}
if (plancnt.integer(forKey: "plancnt") <= 1) {
two.isEnabled = false
three.isEnabled = false
four.isEnabled = false
five.isEnabled = false
six.isEnabled = false
seven.isEnabled = false
eight.isEnabled = false
nine.isEnabled = false
ten.isEnabled = false
elleven.isEnabled = false
twelve.isEnabled = false
thirteen.isEnabled = false
fourteen.isEnabled = false
fifteen.isEnabled = false
sixteen.isEnabled = false
seventeen.isEnabled = false
eighteen.isEnabled = false
nineteen.isEnabled = false
twenty.isEnabled = false
}
if (plancnt.integer(forKey: "plancnt") <= 2) {
three.isEnabled = false
four.isEnabled = false
five.isEnabled = false
six.isEnabled = false
seven.isEnabled = false
eight.isEnabled = false
nine.isEnabled = false
ten.isEnabled = false
elleven.isEnabled = false
twelve.isEnabled = false
thirteen.isEnabled = false
fourteen.isEnabled = false
fifteen.isEnabled = false
sixteen.isEnabled = false
seventeen.isEnabled = false
eighteen.isEnabled = false
nineteen.isEnabled = false
twenty.isEnabled = false
}
if (plancnt.integer(forKey: "plancnt") <= 3) {
four.isEnabled = false
five.isEnabled = false
six.isEnabled = false
seven.isEnabled = false
eight.isEnabled = false
nine.isEnabled = false
ten.isEnabled = false
elleven.isEnabled = false
twelve.isEnabled = false
thirteen.isEnabled = false
fourteen.isEnabled = false
fifteen.isEnabled = false
sixteen.isEnabled = false
seventeen.isEnabled = false
eighteen.isEnabled = false
nineteen.isEnabled = false
twenty.isEnabled = false
}
if (plancnt.integer(forKey: "plancnt") <= 4) {
five.isEnabled = false
six.isEnabled = false
seven.isEnabled = false
eight.isEnabled = false
nine.isEnabled = false
ten.isEnabled = false
elleven.isEnabled = false
twelve.isEnabled = false
thirteen.isEnabled = false
fourteen.isEnabled = false
fifteen.isEnabled = false
sixteen.isEnabled = false
seventeen.isEnabled = false
eighteen.isEnabled = false
nineteen.isEnabled = false
twenty.isEnabled = false
}
if (plancnt.integer(forKey: "plancnt") <= 5) {
six.isEnabled = false
seven.isEnabled = false
eight.isEnabled = false
nine.isEnabled = false
ten.isEnabled = false
elleven.isEnabled = false
twelve.isEnabled = false
thirteen.isEnabled = false
fourteen.isEnabled = false
fifteen.isEnabled = false
sixteen.isEnabled = false
seventeen.isEnabled = false
eighteen.isEnabled = false
nineteen.isEnabled = false
twenty.isEnabled = false
}
if (plancnt.integer(forKey: "plancnt") <= 6) {
seven.isEnabled = false
eight.isEnabled = false
nine.isEnabled = false
ten.isEnabled = false
elleven.isEnabled = false
twelve.isEnabled = false
thirteen.isEnabled = false
fourteen.isEnabled = false
fifteen.isEnabled = false
sixteen.isEnabled = false
seventeen.isEnabled = false
eighteen.isEnabled = false
nineteen.isEnabled = false
twenty.isEnabled = false
}
if (plancnt.integer(forKey: "plancnt") <= 7) {
eight.isEnabled = false
nine.isEnabled = false
ten.isEnabled = false
elleven.isEnabled = false
twelve.isEnabled = false
thirteen.isEnabled = false
fourteen.isEnabled = false
fifteen.isEnabled = false
sixteen.isEnabled = false
seventeen.isEnabled = false
eighteen.isEnabled = false
nineteen.isEnabled = false
twenty.isEnabled = false
}
if (plancnt.integer(forKey: "plancnt") <= 8) {
nine.isEnabled = false
ten.isEnabled = false
elleven.isEnabled = false
twelve.isEnabled = false
thirteen.isEnabled = false
fourteen.isEnabled = false
fifteen.isEnabled = false
sixteen.isEnabled = false
seventeen.isEnabled = false
eighteen.isEnabled = false
nineteen.isEnabled = false
twenty.isEnabled = false
}
if (plancnt.integer(forKey: "plancnt") <= 9) {
ten.isEnabled = false
elleven.isEnabled = false
twelve.isEnabled = false
thirteen.isEnabled = false
fourteen.isEnabled = false
fifteen.isEnabled = false
sixteen.isEnabled = false
seventeen.isEnabled = false
eighteen.isEnabled = false
nineteen.isEnabled = false
twenty.isEnabled = false
}
if (plancnt.integer(forKey: "plancnt") <= 10) {
elleven.isEnabled = false
twelve.isEnabled = false
thirteen.isEnabled = false
fourteen.isEnabled = false
fifteen.isEnabled = false
sixteen.isEnabled = false
seventeen.isEnabled = false
eighteen.isEnabled = false
nineteen.isEnabled = false
twenty.isEnabled = false
}
if (plancnt.integer(forKey: "plancnt") <= 11) {
twelve.isEnabled = false
thirteen.isEnabled = false
fourteen.isEnabled = false
fifteen.isEnabled = false
sixteen.isEnabled = false
seventeen.isEnabled = false
eighteen.isEnabled = false
nineteen.isEnabled = false
twenty.isEnabled = false
}
if (plancnt.integer(forKey: "plancnt") <= 12) {
thirteen.isEnabled = false
fourteen.isEnabled = false
fifteen.isEnabled = false
sixteen.isEnabled = false
seventeen.isEnabled = false
eighteen.isEnabled = false
nineteen.isEnabled = false
twenty.isEnabled = false
}
if (plancnt.integer(forKey: "plancnt") <= 13) {
fourteen.isEnabled = false
fifteen.isEnabled = false
sixteen.isEnabled = false
seventeen.isEnabled = false
eighteen.isEnabled = false
nineteen.isEnabled = false
twenty.isEnabled = false
}
if (plancnt.integer(forKey: "plancnt") <= 14) {
fifteen.isEnabled = false
sixteen.isEnabled = false
seventeen.isEnabled = false
eighteen.isEnabled = false
nineteen.isEnabled = false
twenty.isEnabled = false
}
if (plancnt.integer(forKey: "plancnt") <= 15) {
sixteen.isEnabled = false
seventeen.isEnabled = false
eighteen.isEnabled = false
nineteen.isEnabled = false
twenty.isEnabled = false
}
if (plancnt.integer(forKey: "plancnt") <= 16) {
seventeen.isEnabled = false
eighteen.isEnabled = false
nineteen.isEnabled = false
twenty.isEnabled = false
}
if (plancnt.integer(forKey: "plancnt") <= 17) {
eighteen.isEnabled = false
nineteen.isEnabled = false
twenty.isEnabled = false
}
if (plancnt.integer(forKey: "plancnt") <= 18) {
nineteen.isEnabled = false
twenty.isEnabled = false
}
if (plancnt.integer(forKey: "plancnt") <= 19) {
twenty.isEnabled = false
}
ただし、ボタンの1を除いてボタンのすべてが無効になっています。私の偉大な/より小さい兆候が間違っているか何か他のものがあれば、私は確信していません。
の下にこれを入力します!あなたは配列について聞いたことがありますか? –
親愛なる神。確かに...何か – Alexander
@OrenEdrich配列を使う! Swift言語ガイドを読んでください。質問がある場合は、ここに戻って助けてください:) – Alexander