###前提・実現したいこと
押したボタンによって計算を変えるようにループ文を書きたいのですが、うまくいきません。現在のコードだと、ビルドはできるのですが、ボタンを押しても押さなくても結果が変化しない状況です。
Buttonのアクションが設定されていないので当たり前なのですが、storyボードから繋ぐ方法を試したのですが、ループ外にしか設定できず、エラーになってしまいました。
初心者なので至らない点などあるかと思いますが、ご教授いただけると幸いです。
※計算は例として適当に入れたものです。
###該当のソースコード
swift
1var price = Double() 2 override func viewDidLoad() { 3 super.viewDidLoad() 4 abc1.tag = 1 5 abc2.tag = 2 6 abc3.tag = 3 7 abc4.tag = 4 8 abc5.tag = 5 9 var choice = [abc1.tag, abc2.tag, abc3.tag, abc4.tag, abc5.tag] 10 11 for var i in 0..<choice.count { 12 if(choice[i] == 1){ 13 price=price+20 14 15 } 16 if(choice[i] == 2){ 17 price=price+30 18 19 //print("the price is ") 20 } 21 if(choice[i] == 3){ 22 price=price+40 23 24 //print("the price is ") 25 } 26 if(choice[i] == 4){ 27 28 price=price+50 29 30 //print("the price is ") 31 } 32 if(choice[i] == 5){ 33 price=price+60 34 35 //print("the price is ") 36 } 37 if(choice[i] == 6){ 38 price=price+70 39 40 //print("the price is ") 41 } 42 43 // Do any additional setup after loading the view, typically from a nib. 44 } 45 46 } 47
###試したこと
storyboadからの接続する記述方法
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/04/24 07:10
2017/04/24 07:27 編集